diff --git a/rma_repair/models/rma_operation.py b/rma_repair/models/rma_operation.py index c16823a0..c48d5693 100644 --- a/rma_repair/models/rma_operation.py +++ b/rma_repair/models/rma_operation.py @@ -11,3 +11,5 @@ class RmaOperation(models.Model): ('no', 'Not required'), ('ordered', 'Based on Ordered Quantities'), ('received', 'Based on Received Quantities')], string="Repair Policy", default='no') + delivery_policy = fields.Selection(selection_add=[ + ('repair', 'Based on Repair Quantities')]) diff --git a/rma_repair/models/rma_order_line.py b/rma_repair/models/rma_order_line.py index cd0d676f..0cc6e46d 100644 --- a/rma_repair/models/rma_order_line.py +++ b/rma_repair/models/rma_order_line.py @@ -55,6 +55,11 @@ class RmaOrderLine(models.Model): repair_count = fields.Integer( compute='_compute_repair_count', string='# of Repairs') + delivery_policy = fields.Selection(selection_add=[ + ('repair', 'Based on Repair Quantities')]) + qty_to_deliver = fields.Float( + compute='_compute_qty_to_deliver') + @api.multi def action_view_repair_order(self): action = self.env.ref('repair.action_repair_order_tree') @@ -80,3 +85,21 @@ class RmaOrderLine(models.Model): ) qty += repair_qty return qty + + @api.onchange('operation_id') + def _onchange_operation_id(self): + result = super(RmaOrderLine, self)._onchange_operation_id() + if self.operation_id: + self.repair_type = self.operation_id.repair_type or 'no' + return result + + @api.multi + @api.depends('move_ids', 'move_ids.state', + 'delivery_policy', 'product_qty', 'type', 'qty_delivered', + 'qty_received', 'repair_ids', 'repair_type', + 'repair_ids.state') + def _compute_qty_to_deliver(self): + res = super(RmaOrderLine, self)._compute_qty_to_deliver() + for rec in self.filtered(lambda l: l.delivery_policy == 'repair'): + rec.qty_to_deliver = rec.qty_repaired - rec.qty_delivered + return res diff --git a/rma_repair/tests/test_rma_repair.py b/rma_repair/tests/test_rma_repair.py index c7386460..2373e68d 100644 --- a/rma_repair/tests/test_rma_repair.py +++ b/rma_repair/tests/test_rma_repair.py @@ -50,7 +50,16 @@ class TestRmaRepair(common.SingleTransactionCase): 'in_route_id': cls.rma_route_cust.id, 'out_route_id': cls.rma_route_cust.id, }) - + cls.operation_3 = cls.rma_op.create({ + 'code': 'TEST', + 'name': 'Deliver after repair', + 'type': 'customer', + 'receipt_policy': 'ordered', + 'repair_type': 'ordered', + 'delivery_policy': 'repair', + 'in_route_id': cls.rma_route_cust.id, + 'out_route_id': cls.rma_route_cust.id, + }) # Create products cls.product_1 = cls.product_obj.create({ 'name': 'Test Product 1', @@ -64,7 +73,12 @@ class TestRmaRepair(common.SingleTransactionCase): 'list_price': 150.0, 'rma_customer_operation_id': cls.operation_2.id, }) - + cls.product_3 = cls.product_obj.create({ + 'name': 'Test Product 3', + 'type': 'product', + 'list_price': 1.0, + 'rma_customer_operation_id': cls.operation_3.id, + }) # Create Invoices: customer_account = cls.acc_obj.search( [('user_type_id', '=', receivable_type.id)], limit=1).id @@ -91,6 +105,24 @@ class TestRmaRepair(common.SingleTransactionCase): 'uom_id': cls.product_2.uom_id.id, 'account_id': customer_account, }) + cls.inv_customer2 = cls.inv_obj.create({ + 'partner_id': customer1.id, + 'account_id': customer_account, + 'type': 'out_invoice', + }) + cls.inv_line_3 = cls.invl_obj.create({ + 'name': cls.product_3.name, + 'product_id': cls.product_3.id, + 'quantity': 1.0, + 'price_unit': 1000.0, + 'invoice_id': cls.inv_customer2.id, + 'uom_id': cls.product_3.uom_id.id, + 'account_id': customer_account, + }) + cls.rma_group_customer_2 = cls.rma_obj.create({ + 'partner_id': customer1.id, + 'type': 'customer', + }) def test_01_add_from_invoice_customer(self): """Test wizard to create RMA from a customer invoice.""" @@ -152,3 +184,32 @@ class TestRmaRepair(common.SingleTransactionCase): self.assertEqual(rma.repair_count, 1) self.assertEqual(rma.qty_to_repair, 0.0) self.assertEqual(rma.qty_repaired, 15.0) + + def test_04_deliver_after_repair(self): + """Only deliver after repair""" + add_inv = self.rma_add_invoice_wiz.with_context({ + 'customer': True, + 'active_ids': self.rma_group_customer_2.id, + 'active_model': 'rma.order', + }).create({ + 'invoice_line_ids': + [(6, 0, self.inv_customer2.invoice_line_ids.ids)], + }) + add_inv.add_lines() + rma = self.rma_group_customer_2.rma_line_ids.filtered( + lambda r: r.product_id == self.product_3) + rma.operation_id = self.operation_3.id + rma._onchange_operation_id() + rma.action_rma_to_approve() + rma.action_rma_approve() + self.assertEqual(rma.qty_to_deliver, 0.0) + make_repair = self.rma_make_repair_wiz.with_context({ + 'customer': True, + 'active_ids': rma.ids, + 'active_model': 'rma.order.line', + }).create({ + 'description': 'Test deliver', + }) + make_repair.make_repair_order() + rma.repair_ids.action_repair_confirm() + self.assertEqual(rma.qty_to_deliver, 1.0) diff --git a/rma_repair/views/rma_order_line_view.xml b/rma_repair/views/rma_order_line_view.xml index 91378289..ff82f7ce 100644 --- a/rma_repair/views/rma_order_line_view.xml +++ b/rma_repair/views/rma_order_line_view.xml @@ -9,7 +9,7 @@