From c9526856246a7bfc2bb677196e17227c8197bd81 Mon Sep 17 00:00:00 2001 From: "Denis Vermylen (dve)" Date: Thu, 20 Oct 2016 15:54:32 +0200 Subject: [PATCH] [FIX] mrp_repair: fix repair "workflow" Workflow was badly removed, before repair invoice method didn't make the stock moves. Corrected the issue and made the moves happen always at the end of reparation, not when the repair reaches the done state (ambiguously named "Repaired"). --- addons/mrp_repair/models/mrp_repair.py | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/addons/mrp_repair/models/mrp_repair.py b/addons/mrp_repair/models/mrp_repair.py index aa8b202077b..de6238e9df4 100644 --- a/addons/mrp_repair/models/mrp_repair.py +++ b/addons/mrp_repair/models/mrp_repair.py @@ -209,7 +209,7 @@ class Repair(models.Model): 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 : + 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'}) @@ -230,7 +230,7 @@ class Repair(models.Model): if self.invoice_method == 'b4repair': self.action_repair_ready() elif self.invoice_method == 'after_repair': - self.action_repair_done() + self.write({'state': 'done'}) return True @api.multi @@ -352,13 +352,13 @@ class Repair(models.Model): """ if self.filtered(lambda repair: repair.state != 'under_repair'): raise UserError(_("Repair must be under repair in order to end reparation.")) - for order in self: - vals = {'repaired': True, 'state': 'done'} - if not order.invoiced and order.invoice_method == 'after_repair': + for repair in self: + repair.write({'repaired': True}) + vals = {'state': 'done'} + vals['move_id'] = repair.action_repair_done().get(repair.id) + if not repair.invoiced and repair.invoice_method == 'after_repair': vals['state'] = '2binvoiced' - elif not order.invoiced and order.invoice_method == 'b4repair': - vals['state'] = 'ready' - order.write(vals) + repair.write(vals) return True @api.multi @@ -368,9 +368,7 @@ class Repair(models.Model): """ if self.filtered(lambda repair: not repair.repaired): - raise UserError(_("Repair must be repaired in order to finalize it.")) - if self.filtered(lambda repair: not repair.invoiced and repair.invoice_method != 'none'): - raise UserError(_("Repair must be invoiced in order to finalize it.")) + raise UserError(_("Repair must be repaired in order to make the product moves.")) res = {} Move = self.env['stock.move'] for repair in self: @@ -400,7 +398,6 @@ class Repair(models.Model): }) moves |= move moves.action_done() - repair.write({'state': 'done', 'move_id': move.id}) res[repair.id] = move.id return res @@ -409,7 +406,6 @@ class RepairLine(models.Model): _name = 'mrp.repair.line' _description = 'Repair Line' - name = fields.Char('Description', required=True) repair_id = fields.Many2one( 'mrp.repair', 'Repair Order Reference',