[IMP] uom: introduces duration unit of measure

This commit introduces the duration (time) units of measures, flagged as internation
unit of measure. We already have the "working time" UoM, but those ones are customizable
and might differ from the International System of Units; indeed, one working day means
8 hours (more or less) for some company.
The rational here is, when we are handling datetime, we need to get the UoM in the Odoo
System to convert the result; for instance, computing the difference between 2 datetimes
will return the number of days (or hours). But you need to match it with an odoo UoM to
extract informations from that value.

This unit of measure 'duration' is like a master data, because existing in the real world
and that many module will depend on.

Task-1971491

closes odoo/odoo#32840

Signed-off-by: Jérome Maes (jem) <jem@openerp.com>
This commit is contained in:
jem-odoo
2019-05-14 12:26:41 +00:00
parent 59059a480f
commit 43d51466c8
2 changed files with 24 additions and 1 deletions
+22
View File
@@ -16,6 +16,10 @@
<field name="name">Working Time</field>
<field name="measure_type">working_time</field>
</record>
<record id="uom_categ_time" model="uom.category">
<field name="name">Time</field>
<field name="measure_type">time</field>
</record>
<record id="uom_categ_length" model="uom.category">
<field name="name">Length / Distance</field>
<field name="measure_type">length</field>
@@ -53,6 +57,24 @@
<field name="uom_type">smaller</field>
</record>
<record id="uom_time_week" model="uom.uom">
<field name="name">Week(s)</field>
<field name="category_id" ref="uom_categ_time"/>
<field name="factor" eval="7.0"/>
<field name="uom_type">bigger</field>
</record>
<record id="uom_time_day" model="uom.uom">
<field name="name">Day(s)</field>
<field name="category_id" ref="uom_categ_time"/>
<field name="factor" eval="1.0"/>
</record>
<record id="uom_time_hour" model="uom.uom">
<field name="name">Hour(s)</field>
<field name="category_id" ref="uom_categ_time"/>
<field name="factor" eval="24.0"/>
<field name="uom_type">smaller</field>
</record>
<record id="product_uom_day" model="uom.uom">
<field name="name">Day(s)</field>
<field eval="uom_categ_wtime" name="category_id"/>
+2 -1
View File
@@ -13,6 +13,7 @@ class UoMCategory(models.Model):
measure_type = fields.Selection([
('unit', 'Units'),
('weight', 'Weight'),
('time', 'Time (Duration)'),
('working_time', 'Working Time'),
('length', 'Length'),
('volume', 'Volume'),
@@ -24,7 +25,7 @@ class UoMCategory(models.Model):
@api.multi
def unlink(self):
if self.filtered(lambda categ: categ.measure_type == 'working_time'):
if self.filtered(lambda categ: categ.measure_type in ['working_time', 'time']):
raise UserError(_("You cannot delete this UoM Category as it is used by the system."))
return super(UoMCategory, self).unlink()