From 6e6e8f1cc47b488efd28967a7804d86f33e26328 Mon Sep 17 00:00:00 2001 From: Pratima Gupta Date: Tue, 26 Sep 2017 16:00:52 -0700 Subject: [PATCH] [IMP] mrp_repair: require lot immediately when creating repair lines Instead of only checking when actually confirming the repair. --- addons/mrp_repair/models/mrp_repair.py | 9 ++++++--- addons/mrp_repair/views/mrp_repair_views.xml | 3 ++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/addons/mrp_repair/models/mrp_repair.py b/addons/mrp_repair/models/mrp_repair.py index c057c69f2f1..429fa4498a7 100644 --- a/addons/mrp_repair/models/mrp_repair.py +++ b/addons/mrp_repair/models/mrp_repair.py @@ -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): diff --git a/addons/mrp_repair/views/mrp_repair_views.xml b/addons/mrp_repair/views/mrp_repair_views.xml index bbe2ffe63b8..201951b1449 100644 --- a/addons/mrp_repair/views/mrp_repair_views.xml +++ b/addons/mrp_repair/views/mrp_repair_views.xml @@ -52,13 +52,14 @@ +