[IMP] repair: Hide lot_id and do not systematically reset lot_id

- Hide lot_id field when product is not tracked
- There was an onchange on the product_id that systematically set the lot_id to `False`.
When giving default values for the lot_id and product_id through the context,
the default value of the lot_id would be overwriten by the onchange.
To fix this, we only reset the lot_id when it is inconsistent with the product_id.

TaskId: 1909413
This commit is contained in:
Antoine Prieels
2019-03-06 06:45:13 +00:00
parent e480406773
commit 8a7b6a4f9c
2 changed files with 3 additions and 2 deletions
+2 -1
View File
@@ -159,7 +159,8 @@ class Repair(models.Model):
@api.onchange('product_id')
def onchange_product_id(self):
self.guarantee_limit = False
self.lot_id = False
if (self.product_id and self.lot_id and self.lot_id.product_id != self.product_id) or not self.product_id:
self.lot_id = False
if self.product_id:
self.product_uom = self.product_id.uom_id.id
+1 -1
View File
@@ -58,7 +58,7 @@
<field name="product_qty"/>
<field name="product_uom" groups="uom.group_uom"/>
</div>
<field name="lot_id" domain="[('product_id', '=', product_id)]" context="{'default_product_id': product_id}" groups="stock.group_production_lot" attrs="{'required': [('tracking', '!=', 'none')], 'readonly': [('state', '=', 'done')]}"/>
<field name="lot_id" domain="[('product_id', '=', product_id)]" context="{'default_product_id': product_id}" groups="stock.group_production_lot" attrs="{'required':[('tracking', 'in', ['serial', 'lot'])], 'invisible': [('tracking', 'not in', ['serial', 'lot'])], 'readonly': [('state', '=', 'done')]}"/>
<field name="partner_id" widget="res_partner_many2one" attrs="{'required':[('invoice_method','!=','none')]}" context="{'show_vat': True}"/>
<field name="address_id" groups="sale.group_delivery_invoice_address"/>
</group>