From 43d51466c858719736c3d2be0c9ef5b4f6244733 Mon Sep 17 00:00:00 2001 From: jem-odoo Date: Fri, 19 Apr 2019 12:49:12 +0000 Subject: [PATCH] [IMP] uom: introduces duration unit of measure MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- addons/uom/data/uom_data.xml | 22 ++++++++++++++++++++++ addons/uom/models/uom_uom.py | 3 ++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/addons/uom/data/uom_data.xml b/addons/uom/data/uom_data.xml index 0e79ad9cce7..22108411e6e 100644 --- a/addons/uom/data/uom_data.xml +++ b/addons/uom/data/uom_data.xml @@ -16,6 +16,10 @@ Working Time working_time + + Time + time + Length / Distance length @@ -53,6 +57,24 @@ smaller + + Week(s) + + + bigger + + + Day(s) + + + + + Hour(s) + + + smaller + + Day(s) diff --git a/addons/uom/models/uom_uom.py b/addons/uom/models/uom_uom.py index 2fb50dd6fe6..77465058468 100644 --- a/addons/uom/models/uom_uom.py +++ b/addons/uom/models/uom_uom.py @@ -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()