[FIX] mrp: prevent editing of readonly locations for MO moves

Issue: In the MO view, the src location for components was editable and
the dest location for byproducts was editable when neither of these
should be.

Due to the same field appearing twice in the same x2many field list,
there were 2 issues:

1. something changed (probably during OWL refactoring) that made it so
   the 2nd invisible field instance of the field was overriding the
   "readonly='1'" property of the 1st instance when it was in the view
   (i.e. when multi-locations is active) [in previous versions this did
   not happen]
2. because of the change by https://github.com/odoo/odoo/commit/168cbe66bee7824bdf389de5c6c680342e27bc6d
   we ensure that these two required fields are always correctly set (to
   the MO's values as per the default when multi-loc is active) when the
   MO's moves are created.

Part of general bugfix task: 2985735

closes odoo/odoo#106542

X-original-commit: 1bb2c44d32e669a9b936da90cbd80721b2c897ef
Related: odoo/enterprise#34396
Signed-off-by: William Henrotin (whe) <whe@odoo.com>
Signed-off-by: Tiffany Chang <tic@odoo.com>
This commit is contained in:
Tiffany Chang (tic)
2022-11-25 17:56:55 +01:00
parent 30fcf9c30a
commit a3e1975074
2 changed files with 6 additions and 4 deletions
+4
View File
@@ -285,11 +285,15 @@ class StockMove(models.Model):
product_id_to_product[values['product_id']] = product
values['location_dest_id'] = mo.production_location_id.id
values['price_unit'] = product.standard_price
if not values.get('location_id'):
values['location_id'] = mo.location_src_id.id
continue
# produced products + byproducts
values['location_id'] = mo.production_location_id.id
values['date'] = mo._get_date_planned_finished()
values['date_deadline'] = mo.date_deadline
if not values.get('location_dest_id'):
values['location_dest_id'] = mo.location_dest_id.id
return super().create(vals_list)
def write(self, vals):
+2 -4
View File
@@ -304,7 +304,7 @@
attrs="{'readonly': ['|', ('state', '=', 'cancel'), '&amp;', ('state', '=', 'done'), ('is_locked', '=', True)]}" options="{'delete': [('state', '=', 'draft')]}">
<tree default_order="is_done, manual_consumption desc, sequence" editable="bottom">
<field name="product_id" force_save="1" required="1" context="{'default_detailed_type': 'product'}" attrs="{'readonly': ['|', '|', ('move_lines_count', '&gt;', 0), ('state', '=', 'cancel'), '&amp;', ('state', '!=', 'draft'), ('additional', '=', False) ]}"/>
<field name="location_id" string="From" readonly="1" groups="stock.group_stock_multi_locations" optional="show"/>
<field name="location_id" string="From" readonly="1" force_save="1" groups="stock.group_stock_multi_locations" optional="show"/>
<!-- test_immediate_validate_uom_2, test_product_produce_different_uom -->
<field name="product_uom" invisible="1"/>
<field name="propagate_cancel" invisible="1"/>
@@ -323,7 +323,6 @@
<field name="is_done" invisible="1"/>
<field name="bom_line_id" invisible="1"/>
<field name="sequence" invisible="1"/>
<field name="location_id" invisible="1"/>
<field name="warehouse_id" invisible="1"/>
<field name="is_locked" invisible="1"/>
<field name="move_lines_count" invisible="1"/>
@@ -373,7 +372,7 @@
<field name="move_byproduct_ids" context="{'default_date': date_planned_finished, 'default_date_deadline': date_deadline, 'default_location_id': production_location_id, 'default_location_dest_id': location_dest_id, 'default_state': 'draft', 'default_production_id': id, 'default_picking_type_id': picking_type_id, 'default_company_id': company_id}" attrs="{'readonly': ['|', ('state', '=', 'cancel'), '&amp;', ('state', '=', 'done'), ('is_locked', '=', True)]}" options="{'delete': [('state', '=', 'draft')]}">
<tree default_order="is_done,sequence" decoration-muted="is_done" editable="bottom">
<field name="product_id" context="{'default_detailed_type': 'product'}" domain="[('id', '!=', parent.product_id)]" required="1"/>
<field name="location_dest_id" string="To" readonly="1" groups="stock.group_stock_multi_locations"/>
<field name="location_dest_id" string="To" readonly="1" force_save="1" groups="stock.group_stock_multi_locations"/>
<field name="company_id" invisible="1"/>
<field name="product_uom_category_id" invisible="1"/>
<field name="name" invisible="1"/>
@@ -392,7 +391,6 @@
<field name="warehouse_id" invisible="1"/>
<field name="is_locked" invisible="1"/>
<field name="move_lines_count" invisible="1"/>
<field name="location_dest_id" domain="[('id', 'child_of', parent.location_dest_id)]" invisible="1"/>
<field name="state" invisible="1" force_save="1"/>
<field name="product_uom_qty" string="To Produce" force_save="1" attrs="{'readonly': ['&amp;', ('parent.state', '!=', 'draft'), '|', '&amp;', ('parent.state', 'not in', ('confirmed', 'progress', 'to_close')), ('parent.is_planned', '!=', True), ('parent.is_locked', '=', True)]}"/>
<field name="quantity_done" string="Produced" attrs="{'column_invisible': [('parent.state', '=', 'draft')], 'readonly': [('has_tracking', '=', True)]}"/>