Skip to content

Commit

Permalink
[IMP] add data product uom week.
Browse files Browse the repository at this point in the history
  • Loading branch information
yweng8111 committed Feb 5, 2024
1 parent 28869fd commit 03c0bd7
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 2 deletions.
6 changes: 6 additions & 0 deletions rental_base/data/product_uom_data.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,11 @@
<field ref="uom.uom_categ_wtime" name="category_id" />
<field name="factor" eval="0.033" />
</record>
<record id="product_uom_week" model="uom.uom">
<field name="name">Week(s)</field>
<field name="uom_type">bigger</field>
<field ref="uom.uom_categ_wtime" name="category_id" />
<field name="factor" eval="0.143" />
</record>
</data>
</odoo>
9 changes: 7 additions & 2 deletions rental_base/i18n/de.po
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 12.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-06-27 07:37+0000\n"
"PO-Revision-Date: 2022-06-27 07:37+0000\n"
"POT-Creation-Date: 2022-12-14 14:28+0000\n"
"PO-Revision-Date: 2022-12-14 14:28+0000\n"
"Last-Translator: <>\n"
"Language-Team: \n"
"Language: \n"
Expand Down Expand Up @@ -597,6 +597,11 @@ msgstr "Lieferantengutschriften"
msgid "Vendors"
msgstr "Lieferanten"

#. module: rental_base
#: model:uom.uom,name:rental_base.product_uom_week
msgid "Week(s)"
msgstr "Woche(n)"

#. module: rental_base
#: model:ir.model.fields,field_description:rental_base.field_update_sale_line_date_line__wizard_id
msgid "Wizard"
Expand Down
5 changes: 5 additions & 0 deletions rental_base/i18n/rental_base.pot
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,11 @@ msgstr ""
msgid "Vendors"
msgstr ""

#. module: rental_base
#: model:uom.uom,name:rental_base.product_uom_week
msgid "Week(s)"
msgstr ""

#. module: rental_base
#: model:ir.model.fields,field_description:rental_base.field_update_sale_line_date_line__wizard_id
msgid "Wizard"
Expand Down
5 changes: 5 additions & 0 deletions rental_base/models/sale.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Part of rental-vertical See LICENSE file for full copyright and licensing details.

import datetime
from math import ceil

from odoo import _, api, exceptions, fields, models
from odoo.exceptions import ValidationError
Expand Down Expand Up @@ -204,10 +205,12 @@ def _prepare_invoice_line(self, qty):
@api.model
def _get_time_uom(self):
uom_month = self.env.ref("rental_base.product_uom_month")
uom_week = self.env.ref("rental_base.product_uom_week")
uom_day = self.env.ref("uom.product_uom_day")
uom_hour = self.env.ref("uom.product_uom_hour")
return {
"month": uom_month,
"week": uom_week,
"day": uom_day,
"hour": uom_hour,
}
Expand All @@ -226,6 +229,8 @@ def _get_number_of_time_unit(self):
# https://www.checkyourmath.com/convert/time/days_months.php
number = ((self.end_date - self.start_date).days + 1) / 30.4167
number = float_round(number, precision_rounding=1)
elif self.product_uom.id == time_uoms["week"].id:
number = ceil(((self.end_date - self.start_date).days + 1) / 7)
return number

@api.multi
Expand Down
1 change: 1 addition & 0 deletions rental_base/tests/stock_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def setUp(self):
self.uom_hour = self.env.ref("uom.product_uom_hour")
self.uom_day = self.env.ref("uom.product_uom_day")
self.uom_month = self.env.ref("rental_base.product_uom_month")
self.uom_week = self.env.ref("rental_base.product_uom_week")
self.uom_unit = self.env.ref("uom.product_uom_unit")
self.uom_kgm = self.env.ref("uom.product_uom_kgm")
self.warehouse0 = self.env.ref("stock.warehouse0")
Expand Down
14 changes: 14 additions & 0 deletions rental_base/tests/test_update_time_rental_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def setUp(self):
self.date_0111 = fields.Date.from_string("2021-01-11")
self.date_0103 = fields.Date.from_string("2021-01-03")
self.date_0112 = fields.Date.from_string("2021-01-12")
self.date_0131 = fields.Date.from_string("2021-01-31")

def test_00_update_time_rental_order(self):
# rental order
Expand Down Expand Up @@ -166,3 +167,16 @@ def test_00_update_time_rental_order(self):
rental_2.in_move_id.date_expected,
fields.Datetime.to_datetime(self.date_0112),
)

def test_00_get_time_unit(self):
rental_order = self._create_rental_order(
self.partnerA.id, self.date_0101, self.date_0131
)
days = rental_order.order_line._get_number_of_time_unit()
rental_order.order_line.product_uom = self.uom_week
weeks = rental_order.order_line._get_number_of_time_unit()
rental_order.order_line.product_uom = self.uom_month
months = rental_order.order_line._get_number_of_time_unit()
self.assertEqual(days, 31)
self.assertEqual(weeks, 5)
self.assertEqual(months, 1)

0 comments on commit 03c0bd7

Please sign in to comment.