summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjdoutreloux <jud@odoo.com>2019-11-07 11:23:18 +0000
committerYannick Tivisse <yti@odoo.com>2020-01-13 11:19:17 +0000
commit52ed0be17e80aa6bcc24d59620dd3462b6d577c3 (patch)
tree40eba75a87dd071b8d59747a2c5d4c90a4f26660
parent34dd971ddc17b4d5eac83f229c587367ed045318 (diff)
[IMP] uom : remove 'measure_type' field
This removes the measure_type field which has become unused and causes issues when users try to add new uom categories. Task-2043927 closes odoo/odoo#41056 Related: odoo/enterprise#6945 Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
-rw-r--r--addons/hr_timesheet/models/res_company.py16
-rw-r--r--addons/l10n_it_edi/data/invoice_it_template.xml2
-rw-r--r--addons/mrp/report/mrp_production_templates.xml5
-rw-r--r--addons/mrp/report/mrp_zebra_production_templates.xml3
-rw-r--r--addons/point_of_sale/views/product_view.xml2
-rw-r--r--addons/stock/report/picking_templates.xml6
-rw-r--r--addons/uom/data/uom_data.xml14
-rw-r--r--addons/uom/models/uom_uom.py29
-rw-r--r--addons/uom/tests/test_uom.py8
-rw-r--r--addons/uom/views/uom_uom_views.xml2
10 files changed, 43 insertions, 44 deletions
diff --git a/addons/hr_timesheet/models/res_company.py b/addons/hr_timesheet/models/res_company.py
index 0d890a77108..8d48a0e4bb1 100644
--- a/addons/hr_timesheet/models/res_company.py
+++ b/addons/hr_timesheet/models/res_company.py
@@ -10,27 +10,29 @@ class ResCompany(models.Model):
@api.model
def _default_project_time_mode_id(self):
uom = self.env.ref('uom.product_uom_hour', raise_if_not_found=False)
+ wtime = self.env.ref('uom.uom_categ_wtime')
if not uom:
- uom = self.env['uom.uom'].search([('measure_type', '=', 'working_time'), ('uom_type', '=', 'reference')], limit=1)
+ uom = self.env['uom.uom'].search([('category_id', '=', wtime.id), ('uom_type', '=', 'reference')], limit=1)
if not uom:
- uom = self.env['uom.uom'].search([('measure_type', '=', 'working_time')], limit=1)
+ uom = self.env['uom.uom'].search([('category_id', '=', wtime.id)], limit=1)
return uom
@api.model
def _default_timesheet_encode_uom_id(self):
uom = self.env.ref('uom.product_uom_hour', raise_if_not_found=False)
+ wtime = self.env.ref('uom.uom_categ_wtime')
if not uom:
- uom = self.env['uom.uom'].search([('measure_type', '=', 'working_time'), ('uom_type', '=', 'reference')], limit=1)
+ uom = self.env['uom.uom'].search([('category_id', '=', wtime.id), ('uom_type', '=', 'reference')], limit=1)
if not uom:
- uom = self.env['uom.uom'].search([('measure_type', '=', 'working_time')], limit=1)
+ uom = self.env['uom.uom'].search([('category_id', '=', wtime.id)], limit=1)
return uom
-
+
project_time_mode_id = fields.Many2one('uom.uom', string='Project Time Unit',
- default=_default_project_time_mode_id, domain=[('measure_type', '=', 'working_time')],
+ default=_default_project_time_mode_id,
help="This will set the unit of measure used in projects and tasks.\n"
"If you use the timesheet linked to projects, don't "
"forget to setup the right unit of measure in your employees.")
timesheet_encode_uom_id = fields.Many2one('uom.uom', string="Timesheet Encoding Unit",
- default=_default_timesheet_encode_uom_id, domain=[('measure_type', '=', 'working_time')], required=True,
+ default=_default_timesheet_encode_uom_id, domain=lambda self: [('category_id', '=', self.env.ref('uom.uom_categ_wtime').id)],
help="""This will set the unit of measure used to encode timesheet. This will simply provide tools
and widgets to help the encoding. All reporting will still be expressed in hours (default value).""")
diff --git a/addons/l10n_it_edi/data/invoice_it_template.xml b/addons/l10n_it_edi/data/invoice_it_template.xml
index 3138e2c8e5a..12c318cc3aa 100644
--- a/addons/l10n_it_edi/data/invoice_it_template.xml
+++ b/addons/l10n_it_edi/data/invoice_it_template.xml
@@ -19,7 +19,7 @@
<t t-if="not line.name" t-esc="'NO NAME'"/>
</Descrizione>
<Quantita t-esc="format_numbers(line.quantity)"/>
- <UnitaMisura t-if="line.product_uom_id.category_id.measure_type != 'unit'" t-esc="line.product_uom_id.name"/>
+ <UnitaMisura t-if="line.product_uom_id.category_id != env.ref('uom.product_uom_categ_unit')" t-esc="line.product_uom_id.name"/>
<PrezzoUnitario t-esc="format_monetary(taxes['total_excluded'], currency)"/>
<ScontoMaggiorazione t-if="line.discount != 0">
<!-- [2.2.1.10] -->
diff --git a/addons/mrp/report/mrp_production_templates.xml b/addons/mrp/report/mrp_production_templates.xml
index de1dfe3d523..f8c2704f925 100644
--- a/addons/mrp/report/mrp_production_templates.xml
+++ b/addons/mrp/report/mrp_production_templates.xml
@@ -108,6 +108,7 @@
<template id="label_production_view_pdf">
<t t-call="web.basic_layout">
<div class="page">
+ <t t-set="uom_categ_unit" t-value="env.ref('uom.product_uom_categ_unit')"/>
<t t-foreach="docs" t-as="production">
<t t-foreach="production.move_finished_ids" t-as="move">
<t t-if="production.state == 'done'">
@@ -117,7 +118,7 @@
<t t-set="move_lines" t-value="move.move_line_ids.filtered(lambda x: x.state != 'done' and x.product_qty)"/>
</t>
<t t-foreach="move_lines" t-as="move_line">
- <t t-if="move_line.product_uom_id.category_id.measure_type == 'unit'">
+ <t t-if="move_line.product_uom_id.category_id == uom_categ_unit">
<t t-set="qty" t-value="int(move_line.qty_done)"/>
</t>
<t t-else="">
@@ -132,7 +133,7 @@
<span t-esc="move.product_id.display_name"/>
<br/>
<span>Quantity:</span>
- <t t-if="move_line.product_uom_id.category_id.measure_type == 'unit'">
+ <t t-if="move_line.product_uom_id.category_id == uom_categ_unit">
<span>1.0</span>
<span t-field="move_line.product_uom_id" groups="uom.group_uom"/>
</t>
diff --git a/addons/mrp/report/mrp_zebra_production_templates.xml b/addons/mrp/report/mrp_zebra_production_templates.xml
index 511048bf743..5244d68e1ab 100644
--- a/addons/mrp/report/mrp_zebra_production_templates.xml
+++ b/addons/mrp/report/mrp_zebra_production_templates.xml
@@ -2,10 +2,11 @@
<odoo>
<data>
<template id="label_production_view">
+ <t t-set="uom_categ_unit" t-value="env.ref('uom.product_uom_categ_unit')"/>
<t t-foreach="docs" t-as="production">
<t t-foreach="production.move_finished_ids" t-as="move">
<t t-foreach="move.move_line_ids" t-as="move_line">
- <t t-if="move_line.product_uom_id.category_id.measure_type == 'unit'">
+ <t t-if="move_line.product_uom_id.category_id == uom_categ_unit">
<t t-set="qty" t-value="int(move_line.qty_done)"/>
</t>
<t t-else="">
diff --git a/addons/point_of_sale/views/product_view.xml b/addons/point_of_sale/views/product_view.xml
index 72ccd3abad0..39b5bbda742 100644
--- a/addons/point_of_sale/views/product_view.xml
+++ b/addons/point_of_sale/views/product_view.xml
@@ -102,7 +102,7 @@
<field name="model">uom.category</field>
<field name="inherit_id" ref="uom.product_uom_categ_tree_view"/>
<field name="arch" type="xml">
- <xpath expr="//field[@name='measure_type']" position="after">
+ <xpath expr="//field[@name='name']" position="after">
<field name="is_pos_groupable" groups="base.group_no_one"/>
</xpath>
</field>
diff --git a/addons/stock/report/picking_templates.xml b/addons/stock/report/picking_templates.xml
index b27daf2fae1..7b41cd08d96 100644
--- a/addons/stock/report/picking_templates.xml
+++ b/addons/stock/report/picking_templates.xml
@@ -2,11 +2,12 @@
<odoo>
<data>
<template id="label_transfer_template_view_zpl">
+ <t t-set="uom_categ_unit" t-value="env.ref('uom.product_uom_categ_unit')"/>
<t t-foreach="docs" t-as="picking">
<t t-foreach="picking.move_lines" t-as="move">
<t t-foreach="move.move_line_ids" t-as="move_line">
- <t t-if="move_line.product_uom_id.category_id.measure_type == 'unit'">
+ <t t-if="move_line.product_uom_id.category_id == uom_categ_unit">
<t t-set="qty" t-value="int(move_line.qty_done)"/>
</t>
<t t-else="">
@@ -39,10 +40,11 @@
<template id="label_transfer_template_view_pdf">
<t t-call="web.basic_layout">
<div class="page">
+ <t t-set="uom_categ_unit" t-value="env.ref('uom.product_uom_categ_unit')"/>
<t t-foreach="docs" t-as="picking">
<t t-foreach="picking.move_lines" t-as="move">
<t t-foreach="move.move_line_ids" t-as="move_line">
- <t t-if="move_line.product_uom_id.category_id.measure_type == 'unit'">
+ <t t-if="move_line.product_uom_id.category_id == uom_categ_unit">
<t t-set="qty" t-value="int(move_line.qty_done)"/>
</t>
<t t-else="">
diff --git a/addons/uom/data/uom_data.xml b/addons/uom/data/uom_data.xml
index badda0920c1..aab34756533 100644
--- a/addons/uom/data/uom_data.xml
+++ b/addons/uom/data/uom_data.xml
@@ -6,23 +6,18 @@
-->
<record id="product_uom_categ_unit" model="uom.category">
<field name="name">Unit</field>
- <field name="measure_type">unit</field>
</record>
<record id="product_uom_categ_kgm" model="uom.category">
<field name="name">Weight</field>
- <field name="measure_type">weight</field>
</record>
<record id="uom_categ_wtime" model="uom.category">
<field name="name">Working Time</field>
- <field name="measure_type">working_time</field>
</record>
<record id="uom_categ_length" model="uom.category">
<field name="name">Length / Distance</field>
- <field name="measure_type">length</field>
</record>
<record id="product_uom_categ_vol" model="uom.category">
<field name="name">Volume</field>
- <field name="measure_type">volume</field>
</record>
<!--
Resource: uom.uom
@@ -31,6 +26,7 @@
<field name="category_id" ref="product_uom_categ_unit"/>
<field name="name">Units</field>
<field name="factor" eval="1.0"/>
+ <field name="uom_type">reference</field>
<field name="rounding" eval="0.001"/>
</record>
<record id="product_uom_dozen" model="uom.uom">
@@ -44,6 +40,7 @@
<field name="category_id" ref="product_uom_categ_kgm"/>
<field name="name">kg</field>
<field name="factor" eval="1"/>
+ <field name="uom_type">reference</field>
<field name="rounding" eval="0.001"/>
</record>
<record id="product_uom_gram" model="uom.uom">
@@ -55,12 +52,13 @@
<record id="product_uom_day" model="uom.uom">
<field name="name">Days</field>
- <field eval="uom_categ_wtime" name="category_id"/>
+ <field name="category_id" ref="uom_categ_wtime"/>
<field name="factor" eval="1.0"/>
+ <field name="uom_type">reference</field>
</record>
<record id="product_uom_hour" model="uom.uom">
<field name="name">Hours</field>
- <field eval="uom_categ_wtime" name="category_id"/>
+ <field name="category_id" ref="uom_categ_wtime"/>
<field name="factor" eval="8.0"/>
<field name="uom_type">smaller</field>
</record>
@@ -76,6 +74,7 @@
<field name="category_id" ref="uom_categ_length"/>
<field name="name">m</field>
<field name="factor" eval="1.0"/>
+ <field name="uom_type">reference</field>
</record>
<record id="product_uom_km" model="uom.uom">
<field name="category_id" ref="uom_categ_length"/>
@@ -93,6 +92,7 @@
<field name="name">Liters</field>
<field name="category_id" ref="product_uom_categ_vol"/>
<field name="factor">1.0</field>
+ <field name="uom_type">reference</field>
</record>
<!--Americanization of units of measure-->
diff --git a/addons/uom/models/uom_uom.py b/addons/uom/models/uom_uom.py
index 5d18143b4f3..c5d105c0fb2 100644
--- a/addons/uom/models/uom_uom.py
+++ b/addons/uom/models/uom_uom.py
@@ -10,20 +10,11 @@ class UoMCategory(models.Model):
_description = 'Product UoM Categories'
name = fields.Char('Unit of Measure Category', required=True, translate=True)
- measure_type = fields.Selection([
- ('unit', 'Default Units'),
- ('weight', 'Default Weight'),
- ('working_time', 'Default Working Time'),
- ('length', 'Default Length'),
- ('volume', 'Default Volume'),
- ], string="Type of Measure")
-
- _sql_constraints = [
- ('uom_category_unique_type', 'UNIQUE(measure_type)', 'You can have only one category per measurement type.'),
- ]
def unlink(self):
- if self.filtered(lambda categ: categ.measure_type == 'working_time'):
+ uom_categ_unit = self.env.ref('uom.product_uom_categ_unit')
+ uom_categ_wtime = self.env.ref('uom.uom_categ_wtime')
+ if any(categ.id in (uom_categ_unit + uom_categ_wtime).ids for categ in self):
raise UserError(_("You cannot delete this UoM Category as it is used by the system."))
return super(UoMCategory, self).unlink()
@@ -54,7 +45,6 @@ class UoM(models.Model):
('reference', 'Reference Unit of Measure for this category'),
('smaller', 'Smaller than the reference Unit of Measure')], 'Type',
default='reference', required=1)
- measure_type = fields.Selection(string="Type of measurement category", related='category_id.measure_type', store=True, readonly=True)
_sql_constraints = [
('factor_gt_zero', 'CHECK (factor!=0)', 'The conversion ratio for a unit of measure cannot be 0!'),
@@ -93,6 +83,15 @@ class UoM(models.Model):
if uom_data['uom_count'] > 1:
raise ValidationError(_("UoM category %s should only have one reference unit of measure.") % (self.env['uom.category'].browse(uom_data['category_id']).name,))
+ @api.constrains('category_id')
+ def _validate_uom_category(self):
+ for uom in self:
+ reference_uoms = self.env['uom.uom'].search([
+ ('category_id', '=', uom.category_id.id),
+ ('uom_type', '=', 'reference')])
+ if len(reference_uoms) > 1:
+ raise ValidationError(_("UoM category %s should only have one reference unit of measure.") % (self.category_id.name))
+
@api.model_create_multi
def create(self, vals_list):
for values in vals_list:
@@ -108,7 +107,9 @@ class UoM(models.Model):
return super(UoM, self).write(values)
def unlink(self):
- if self.filtered(lambda uom: uom.measure_type == 'working_time'):
+ uom_categ_unit = self.env.ref('uom.product_uom_categ_unit')
+ uom_categ_wtime = self.env.ref('uom.uom_categ_wtime')
+ if any(uom.category_id.id in (uom_categ_unit + uom_categ_wtime).ids and uom.uom_type == 'reference' for uom in self):
raise UserError(_("You cannot delete this UoM as it is used by the system. You should rather archive it."))
return super(UoM, self).unlink()
diff --git a/addons/uom/tests/test_uom.py b/addons/uom/tests/test_uom.py
index 935bb6a12cb..48728b18bcd 100644
--- a/addons/uom/tests/test_uom.py
+++ b/addons/uom/tests/test_uom.py
@@ -51,7 +51,7 @@ class TestUom(TransactionCase):
def test_30_reference_uniqueness(self):
""" Check the uniqueness of the reference UoM in a category """
- time_category = self.env['uom.category'].search([('measure_type', '=', 'working_time')], limit=1)
+ time_category = self.env.ref('uom.product_uom_categ_unit')
with self.assertRaises(ValidationError):
self.env['uom.uom'].create({
@@ -62,12 +62,6 @@ class TestUom(TransactionCase):
'category_id': time_category.id
})
- def test_31_reference_uniqueness(self):
- """ Check the uniqueness of the reference UoM in a category """
- time_category = self.env['uom.category'].search([('measure_type', '=', 'working_time')], limit=1)
- with self.assertRaises(ValidationError):
- self.env['uom.uom'].search([('measure_type', '=', 'unit'), ('uom_type', '=', 'reference')]).category_id = time_category
-
def test_40_custom_uom(self):
""" A custom UoM is an UoM in a category without measurement type. It should behave like a normal UoM """
category = self.env['uom.category'].create({
diff --git a/addons/uom/views/uom_uom_views.xml b/addons/uom/views/uom_uom_views.xml
index 84154a055f7..cf835c1dfb1 100644
--- a/addons/uom/views/uom_uom_views.xml
+++ b/addons/uom/views/uom_uom_views.xml
@@ -90,7 +90,6 @@
<sheet>
<group>
<field name="name"/>
- <field name="measure_type"/>
</group>
</sheet>
</form>
@@ -103,7 +102,6 @@
<field name="arch" type="xml">
<tree string="Units of Measure categories" editable="bottom">
<field name="name"/>
- <field name="measure_type" groups="base.group_no_one"/>
</tree>
</field>
</record>