Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][FIX] rma: group rma receptions #423

Open
wants to merge 1 commit into
base: 16.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a help string should be great

)
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
24 changes: 24 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 @@ -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(
Expand Down Expand Up @@ -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
)
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
29 changes: 29 additions & 0 deletions rma_sale/tests/test_rma_sale.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ def setUpClass(cls):
cls.rma_operation_model = cls.env["rma.operation"]
cls.operation = cls.env.ref("rma.rma_operation_replace")
cls._partner_portal_wizard(cls, cls.partner)
cls.wh = cls.env.ref("stock.warehouse0")
cls.env["stock.quant"]._update_available_quantity(
cls.product_1, cls.wh.lot_stock_id, 20
)
cls.env["stock.quant"]._update_available_quantity(
cls.product_2, cls.wh.lot_stock_id, 20
)

def _create_sale_order(self, products):
order_form = Form(self.so_model)
Expand Down Expand Up @@ -222,3 +229,25 @@ def test_report_rma(self):
res = str(res[0])
self.assertRegex(res, self.sale_order.name)
self.assertRegex(res, operation.name)

def test_grouping_reception_disabled(self):
self.env.company.rma_reception_grouping = False
sale_order = self._create_sale_order([[self.product_1, 5], [self.product_2, 3]])
sale_order.action_confirm()
sale_order.picking_ids.action_set_quantities_to_reservation()
sale_order.picking_ids.button_validate()
wizard = self._rma_sale_wizard(sale_order)
rmas = self.env["rma"].search(wizard.create_and_open_rma()["domain"])
self.assertEqual(len(rmas.reception_move_id.group_id), 2)
self.assertEqual(len(rmas.reception_move_id.picking_id), 2)

def test_grouping_reception_enabled(self):
self.env.company.rma_reception_grouping = True
sale_order = self._create_sale_order([[self.product_1, 5], [self.product_2, 3]])
sale_order.action_confirm()
sale_order.picking_ids.action_set_quantities_to_reservation()
sale_order.picking_ids.button_validate()
wizard = self._rma_sale_wizard(sale_order)
rmas = self.env["rma"].search(wizard.create_and_open_rma()["domain"])
self.assertEqual(len(rmas.reception_move_id.group_id), 1)
self.assertEqual(len(rmas.reception_move_id.picking_id), 1)
3 changes: 1 addition & 2 deletions rma_sale/wizard/sale_order_rma_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ def create_and_open_rma(self):
rma = self.create_rma()
if not rma:
return
for rec in rma:
rec.action_confirm()
rma.action_confirm()
action = self.sudo().env.ref("rma.rma_action").read()[0]
if len(rma) > 1:
action["domain"] = [("id", "in", rma.ids)]
Expand Down
Loading