Skip to content

Commit

Permalink
[FIX] rma: group rma receptions
Browse files Browse the repository at this point in the history
  • Loading branch information
sbejaoui committed Aug 29, 2024
1 parent 6197962 commit c9815df
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 5 deletions.
3 changes: 3 additions & 0 deletions rma/models/res_company.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions rma/models/res_config_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions rma/models/rma.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
23 changes: 23 additions & 0 deletions rma/tests/test_rma.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -848,3 +851,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
)
16 changes: 16 additions & 0 deletions rma/views/res_config_settings_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,22 @@
</div>
</div>
</div>
<div class="col-12 col-lg-6 o_setting_box">
<div class="o_setting_left_pane">
<field name="rma_reception_grouping" />
</div>
<div class="o_setting_right_pane">
<label for="rma_reception_grouping" />
<span
class="fa fa-lg fa-building-o"
title="Values set here are company-specific."
groups="base.group_multi_company"
/>
<div class="text-muted">
Enable this option to group multiple RMAs into a single reception picking, simplifying the management of returns when items are received together.
</div>
</div>
</div>
<div
class="col-12 col-lg-6 o_setting_box"
title="Send automatic RMA info to customer"
Expand Down
5 changes: 0 additions & 5 deletions rma/wizard/stock_picking_return.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,6 @@ def _prepare_rma_partner_values(self):
def _prepare_rma_vals(self):
partner, partner_invoice, partner_shipping = self._prepare_rma_partner_values()
origin = self.picking_id.name
vals = self.env["rma"]._prepare_procurement_group_vals()
vals["partner_id"] = partner_shipping.id
vals["name"] = origin
group = self.env["procurement.group"].create(vals)
return {
"user_id": self.env.user.id,
"partner_id": partner.id,
Expand All @@ -111,7 +107,6 @@ def _prepare_rma_vals(self):
"origin": origin,
"picking_id": self.picking_id.id,
"company_id": self.company_id.id,
"procurement_group_id": group.id,
}

def _prepare_rma_vals_list(self):
Expand Down

0 comments on commit c9815df

Please sign in to comment.