Skip to content
Snippets Groups Projects
Unverified Commit 6e6e8f1c authored by Pratima Gupta's avatar Pratima Gupta Committed by Joren Van Onder
Browse files

[IMP] mrp_repair: require lot immediately when creating repair lines

Instead of only checking when actually confirming the repair.
parent 578ebc6f
Branches
Tags
No related merge requests found
......@@ -116,6 +116,7 @@ class Repair(models.Model):
amount_untaxed = fields.Float('Untaxed Amount', compute='_amount_untaxed', store=True)
amount_tax = fields.Float('Taxes', compute='_amount_tax', store=True)
amount_total = fields.Float('Total', compute='_amount_total', store=True)
tracking = fields.Selection('Product Tracking', related="product_id.tracking")
@api.one
@api.depends('partner_id')
......@@ -215,9 +216,6 @@ class Repair(models.Model):
before_repair.write({'state': '2binvoiced'})
to_confirm = self - before_repair
to_confirm_operations = to_confirm.mapped('operations')
for operation in to_confirm_operations:
if operation.product_id.tracking != 'none' and not operation.lot_id:
raise UserError(_("Serial number is required for operation line with product '%s'") % (operation.product_id.name))
to_confirm_operations.write({'state': 'confirmed'})
to_confirm.write({'state': 'confirmed'})
return True
......@@ -513,6 +511,11 @@ class RepairLine(models.Model):
copy=False, readonly=True, required=True,
help='The status of a repair line is set automatically to the one of the linked repair order.')
@api.constrains('lot_id', 'product_id')
def constrain_lot_id(self):
for line in self.filtered(lambda x: x.product_id.tracking != 'none' and not x.lot_id):
raise ValidationError(_("Serial number is required for operation line with product '%s'") % (line.product_id.name))
@api.one
@api.depends('price_unit', 'repair_id', 'product_uom_qty', 'product_id', 'repair_id.invoice_method')
def _compute_price_subtotal(self):
......
......@@ -52,13 +52,14 @@
</h1>
<group>
<group>
<field name="tracking" invisible="1"/>
<field name="product_id" domain="[('type', 'in', ['product', 'consu'])]"/>
<label for="product_qty"/>
<div class="o_row">
<field name="product_qty"/>
<field name="product_uom" groups="product.group_uom"/>
</div>
<field name="lot_id" domain="[('product_id', '=', product_id)]" context="{'default_product_id': product_id}" groups="stock.group_production_lot"/>
<field name="lot_id" domain="[('product_id', '=', product_id)]" context="{'default_product_id': product_id}" groups="stock.group_production_lot" attrs="{'required': [('tracking', '!=', 'none')]}"/>
<field name="partner_id" attrs="{'required':[('invoice_method','!=','none')]}"/>
<field name="address_id" groups="sale.group_delivery_invoice_address"/>
</group>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment