Skip to content

Commit

Permalink
[IMP] uom: introduces duration unit of measure
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jem-odoo committed May 14, 2019
1 parent f84b742 commit 92df16a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
22 changes: 22 additions & 0 deletions addons/uom/data/uom_data.xml
Expand Up @@ -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>
Expand Down Expand Up @@ -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"/>
Expand Down
3 changes: 2 additions & 1 deletion addons/uom/models/uom_uom.py
Expand Up @@ -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'),
Expand All @@ -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()

Expand Down

0 comments on commit 92df16a

Please sign in to comment.