[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>
This commit is contained in:
jdoutreloux
2020-01-13 11:19:17 +00:00
committed by Yannick Tivisse
parent 34dd971ddc
commit 52ed0be17e
10 changed files with 43 additions and 44 deletions
+9 -7
View File
@@ -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).""")
@@ -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] -->
@@ -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>
@@ -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="">
+1 -1
View File
@@ -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>
+4 -2
View File
@@ -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="">
+7 -7
View File
@@ -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-->
+15 -14
View File
@@ -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()
+1 -7
View File
@@ -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({
-2
View File
@@ -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>