[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
e1f518bb83 but the ability to add new
workorder lines conditionnaly in the workorder form view was missing.

Task: 2121714
This commit is contained in:
William Henrotin
2020-01-30 12:40:38 +00:00
parent 4cfcc36d0e
commit f37ae92cd6
2 changed files with 9 additions and 2 deletions
+7
View File
@@ -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)
+2 -2
View File
@@ -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"/>