diff --git a/rma/__manifest__.py b/rma/__manifest__.py index 545b1b5e..546821de 100644 --- a/rma/__manifest__.py +++ b/rma/__manifest__.py @@ -10,7 +10,7 @@ "in odoo", "author": "ForgeFlow", "website": "https://github.com/ForgeFlow/stock-rma", - "depends": ["stock", "mail", "web"], + "depends": ["stock", "mail", "web", "account"], "demo": ["demo/stock_demo.xml"], "data": [ "security/rma.xml", diff --git a/rma/models/product.py b/rma/models/product.py index 418e6860..c4055c5b 100644 --- a/rma/models/product.py +++ b/rma/models/product.py @@ -8,10 +8,14 @@ class ProductTemplate(models.Model): _inherit = "product.template" rma_customer_operation_id = fields.Many2one( - comodel_name="rma.operation", string="Default RMA Customer Operation" + company_dependent=True, + comodel_name="rma.operation", + string="Default RMA Customer Operation", ) rma_supplier_operation_id = fields.Many2one( - comodel_name="rma.operation", string="Default RMA Supplier Operation" + company_dependent=True, + comodel_name="rma.operation", + string="Default RMA Supplier Operation", ) rma_approval_policy = fields.Selection( related="categ_id.rma_approval_policy", readonly=True diff --git a/rma/models/product_category.py b/rma/models/product_category.py index b528731c..db832c2e 100644 --- a/rma/models/product_category.py +++ b/rma/models/product_category.py @@ -19,8 +19,12 @@ class ProductCategory(models.Model): "this policy will request the RMA manager approval.", ) rma_customer_operation_id = fields.Many2one( - comodel_name="rma.operation", string="Default RMA Customer Operation" + company_dependent=True, + comodel_name="rma.operation", + string="Default RMA Customer Operation", ) rma_supplier_operation_id = fields.Many2one( - comodel_name="rma.operation", string="Default RMA Supplier Operation" + company_dependent=True, + comodel_name="rma.operation", + string="Default RMA Supplier Operation", ) diff --git a/rma/tests/test_rma.py b/rma/tests/test_rma.py index faa3dd4d..310c5888 100644 --- a/rma/tests/test_rma.py +++ b/rma/tests/test_rma.py @@ -980,4 +980,41 @@ class TestRma(common.SavepointCase): ) for line in self.rma_supplier_id.rma_line_ids: line.action_rma_done() - self.assertEqual(line.mapped("state"), ["done"], "Wrong State") + self.assertEqual(line.state, "done", "Wrong State") + + def test_05_rma_order_line(self): + """Property rma_customer_operation_id on product or product category + correctly handled inside _onchange_product_id() + """ + rma_operation = self.env["rma.operation"].search([], limit=1) + self.assertTrue(rma_operation) + + # Case of product template + self.rma_customer_id.rma_line_ids.mapped("product_id").sudo().write( + {"rma_customer_operation_id": rma_operation.id} + ) + for line in self.rma_customer_id.rma_line_ids: + data = {"product_id": line.product_id.id} + new_line = self.rma_line.new(data) + self.assertFalse(new_line.operation_id) + self.assertTrue(new_line.product_id.rma_customer_operation_id) + self.assertTrue(new_line.product_id.categ_id.rma_customer_operation_id) + new_line._onchange_product_id() + self.assertEqual(new_line.operation_id, rma_operation) + + # Case of product category + self.rma_customer_id.rma_line_ids.mapped("product_id").sudo().write( + {"rma_customer_operation_id": False} + ) + self.rma_customer_id.rma_line_ids.mapped("product_id.categ_id").sudo().write( + {"rma_customer_operation_id": rma_operation.id} + ) + + for line in self.rma_customer_id.rma_line_ids: + data = {"product_id": line.product_id.id} + new_line = self.rma_line.new(data) + self.assertFalse(new_line.operation_id) + self.assertFalse(new_line.product_id.rma_customer_operation_id) + self.assertTrue(new_line.product_id.categ_id.rma_customer_operation_id) + new_line._onchange_product_id() + self.assertEqual(new_line.operation_id, rma_operation)