diff --git a/rma/models/res_company.py b/rma/models/res_company.py index 2b55930a3..941db2e1e 100644 --- a/rma/models/res_company.py +++ b/rma/models/res_company.py @@ -26,6 +26,9 @@ def _default_rma_mail_draft_template(self): except ValueError: return False + rma_reception_grouping = fields.Boolean( + string="Group RMA receptions", default=False + ) rma_return_grouping = fields.Boolean( string="Group RMA returns by customer address and warehouse", default=True, diff --git a/rma/models/res_config_settings.py b/rma/models/res_config_settings.py index c06d9e594..44c79ae3c 100644 --- a/rma/models/res_config_settings.py +++ b/rma/models/res_config_settings.py @@ -11,6 +11,9 @@ class ResConfigSettings(models.TransientModel): help="Allow to finish an RMA without returning back a product or refunding", implied_group="rma.group_rma_manual_finalization", ) + rma_reception_grouping = fields.Boolean( + related="company_id.rma_reception_grouping", readonly=False + ) rma_return_grouping = fields.Boolean( related="company_id.rma_return_grouping", readonly=False, diff --git a/rma/models/rma.py b/rma/models/rma.py index 5921848e9..3018710f9 100644 --- a/rma/models/rma.py +++ b/rma/models/rma.py @@ -732,6 +732,10 @@ def action_confirm(self): self = self.filtered(lambda rma: rma.state == "draft") if not self: return + if self.env.company.rma_reception_grouping: + self.procurement_group_id = self.env["procurement.group"].create( + self._prepare_procurement_group_vals() + ) procurements = self._prepare_reception_procurements() if procurements: self.env["procurement.group"].run(procurements) diff --git a/rma/tests/test_rma.py b/rma/tests/test_rma.py index 7b798fcb8..c4ac734ff 100644 --- a/rma/tests/test_rma.py +++ b/rma/tests/test_rma.py @@ -38,6 +38,9 @@ def setUpClass(cls): cls.product = cls.product_product.create( {"name": "Product test 1", "type": "product"} ) + cls.product_2 = cls.product_product.create( + {"name": "Product test 2", "type": "product"} + ) cls.account_receiv = cls.env["account.account"].create( { "name": "Receivable", @@ -691,6 +694,7 @@ def test_mass_return_to_customer_ungrouped(self): self.assertEqual(4, len(all_rmas.delivery_move_ids.picking_id)) def test_rma_from_picking_return(self): + self.env.company.rma_reception_grouping = True # Create a return from a delivery picking origin_delivery = self._create_delivery() stock_return_picking_form = Form( @@ -848,3 +852,23 @@ def test_autoconfirm_email(self): ) self.assertTrue(rma.name in mail_receipt.subject) self.assertTrue("products received" in mail_receipt.subject) + + def test_grouping_reception_disabled(self): + self.env.company.rma_reception_grouping = False + rma_1 = self._create_rma(self.partner, self.product, 10, self.rma_loc) + rma_2 = self._create_rma(self.partner, self.product_2, 10, self.rma_loc) + (rma_1 | rma_2).action_confirm() + self.assertTrue(rma_1.reception_move_id.picking_id) + self.assertTrue(rma_2.reception_move_id.picking_id) + self.assertNotEqual( + rma_1.reception_move_id.picking_id, rma_2.reception_move_id.picking_id + ) + + def test_grouping_reception_enabled(self): + self.env.company.rma_reception_grouping = True + rma_1 = self._create_rma(self.partner, self.product, 10, self.rma_loc) + rma_2 = self._create_rma(self.partner, self.product_2, 10, self.rma_loc) + (rma_1 | rma_2).action_confirm() + self.assertEqual( + rma_1.reception_move_id.picking_id, rma_2.reception_move_id.picking_id + ) diff --git a/rma/views/res_config_settings_views.xml b/rma/views/res_config_settings_views.xml index fbaa21b7b..b195221a0 100644 --- a/rma/views/res_config_settings_views.xml +++ b/rma/views/res_config_settings_views.xml @@ -39,6 +39,22 @@ +