summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam Henrotin <whe@odoo.com>2020-01-27 10:18:58 +0000
committerWilliam Henrotin <whe@odoo.com>2020-01-30 12:40:38 +0000
commitf37ae92cd68cd61a8f4a46196dfba82f2872d72e (patch)
treeec9dd344fd0e23e3ef8946659ba2cdde226f14f6
parent4cfcc36d0e241b2b608453b290ec575444724c60 (diff)
[IMP] mrp: Add new components in workorders
Purpose: adding new component in a specific workorder via the form view. This behavior is only available if the Bill of Material is in flexible consumption. Adding new component was already made possible in e1f518bb83ccaa2abf08bc870bc1c7345e85971c but the ability to add new workorder lines conditionnaly in the workorder form view was missing. Task: 2121714
-rw-r--r--addons/mrp/models/mrp_workorder.py7
-rw-r--r--addons/mrp/views/mrp_workorder_views.xml4
2 files changed, 9 insertions, 2 deletions
diff --git a/addons/mrp/models/mrp_workorder.py b/addons/mrp/models/mrp_workorder.py
index e410190663e..74d9da400a5 100644
--- a/addons/mrp/models/mrp_workorder.py
+++ b/addons/mrp/models/mrp_workorder.py
@@ -789,6 +789,13 @@ class MrpWorkorderLine(models.Model):
finished_workorder_id = fields.Many2one('mrp.workorder', 'Finished Product for Workorder',
ondelete='cascade')
+ @api.onchange('qty_to_consume')
+ def _onchange_qty_to_consume(self):
+ # Update qty_done for products added in ready state
+ wo = self.raw_workorder_id or self.finished_workorder_id
+ if wo.state == 'ready':
+ self.qty_done = self.qty_to_consume
+
@api.model_create_multi
def create(self, vals_list):
res = super().create(vals_list)
diff --git a/addons/mrp/views/mrp_workorder_views.xml b/addons/mrp/views/mrp_workorder_views.xml
index 16d9ae58fd4..3deec91fca8 100644
--- a/addons/mrp/views/mrp_workorder_views.xml
+++ b/addons/mrp/views/mrp_workorder_views.xml
@@ -217,13 +217,13 @@
</group>
</group>
<h4 attrs="{'invisible': ['&amp;', ('consumption', '=', 'strict'), ('raw_workorder_line_ids', '=', [])]}">Components</h4>
- <field name="raw_workorder_line_ids" attrs="{'invisible': ['&amp;', ('consumption', '=', 'strict'), ('raw_workorder_line_ids', '=', [])], 'readonly': [('state', 'in', ('cancel', 'done'))]}">
+ <field name="raw_workorder_line_ids" attrs="{'invisible': ['&amp;', ('consumption', '=', 'strict'), ('raw_workorder_line_ids', '=', [])], 'readonly': [('state', 'in', ('cancel', 'done'))]}" options="{'create': [('consumption', '=', 'flexible')]}">
<tree editable="bottom" create="1" delete="0">
<field name="product_id"/>
<field name="product_tracking" invisible="1"/>
<field name="company_id" invisible="1"/>
<field name="lot_id" attrs="{'readonly': [('product_tracking', '=', 'none')]}" context="{'default_company_id': company_id, 'default_product_id': product_id, 'active_mo_id': parent.production_id}"/>
- <field name="qty_to_consume" readonly="1" force_save="1"/>
+ <field name="qty_to_consume" attrs="{'readonly': [('parent.consumption', '=', 'strict')]}" force_save="1"/>
<field name="qty_reserved" readonly="1"/>
<field name="qty_done" attrs="{'column_invisible': [('parent.state', 'not in', ('progress', 'done'))]}"/>
<field name="product_uom_id" invisible="1"/>