Skip to content

Commit

Permalink
[16.0][IMP] rma, add feature to require origin field in rma approval …
Browse files Browse the repository at this point in the history
…process
  • Loading branch information
ChrisOForgeFlow committed Sep 25, 2024
1 parent 44a3669 commit 73cc3b6
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 0 deletions.
4 changes: 4 additions & 0 deletions rma/models/rma_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,7 @@ def _default_routes(self):
required=True,
default=lambda self: self.env.user.company_id,
)
require_origin_field_filled = fields.Boolean(
default=False,
help="RMA document can't be continue in process if at least one origin field is filled",
)
12 changes: 12 additions & 0 deletions rma/models/rma_order_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -647,8 +647,20 @@ def _check_lot_assigned(self):
% (rec.product_id.display_name)
)

@api.model
def _origin_fields(self):
return ["reference_move_id"]

def _check_origin_fields_filled(self):
for rec in self.filtered(lambda x: x.operation_id.require_origin_field_filled):
if not any(rec[origin_field] for origin_field in self._origin_fields()):
raise UserError(
_("You should fill at least one origin field to continue")
)

def action_rma_to_approve(self):
self._check_lot_assigned()
self._check_origin_fields_filled()
self.write({"state": "to_approve"})
for rec in self:
if rec.product_id.rma_approval_policy == "one_step":
Expand Down
41 changes: 41 additions & 0 deletions rma/tests/test_rma.py
Original file line number Diff line number Diff line change
Expand Up @@ -1093,3 +1093,44 @@ def test_09_rma_state(self):
self.assertEqual(
rma.rma_line_ids.mapped("state"), ["approved", "approved", "approved"]
)

def test_10_rma_require_origin_fields(self):
self.rma_cust_replace_op_id.write(
{
"require_origin_field_filled": True,
}
)
rma_line = Form(
self.rma_line.with_user(self.rma_basic_user),
view=self.env.ref("rma.view_rma_line_form").id,
)
rma_line.partner_id = self.partner_id
rma_line.operation_id = self.rma_cust_replace_op_id
rma_line.product_id = self.product_1
rma_line = rma_line.save()
with self.assertRaises(UserError):
rma_line.action_rma_to_approve()

self._create_inventory(self.product_1, 5, self.stock_location)
picking_type = self._get_picking_type(
self.wh, self.stock_location, self.customer_location
)
picking = self._create_picking(self.partner_id, picking_type)
move_values = self._prepare_move(
self.product_1,
5,
self.stock_location,
self.customer_location,
picking,
)
move_created = self.env["stock.move"].create(move_values)
self._do_picking(picking)

rma_line = Form(
rma_line.with_user(self.rma_basic_user),
view=self.env.ref("rma.view_rma_line_form").id,
)
rma_line.reference_move_id = move_created
rma_line = rma_line.save()
rma_line.action_rma_to_approve()
self.assertIn(rma_line.state, ("to_approve", "approved"))
1 change: 1 addition & 0 deletions rma/views/rma_operation_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
<group name="policies" string="Policies">
<field name="receipt_policy" />
<field name="delivery_policy" />
<field name="require_origin_field_filled" />
</group>
<group name="inbound" string="Inbound">
<field name="in_route_id" />
Expand Down
5 changes: 5 additions & 0 deletions rma_account/models/rma_order_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ def _compute_refund_count(self):
ondelete="restrict",
)

@api.model
def _origin_fields(self):
res = super()._origin_fields()
return res + ["account_move_line_id"]

@api.depends("partner_id")
def _compute_commercial_partner_id(self):
for rma_line in self:
Expand Down
5 changes: 5 additions & 0 deletions rma_purchase/models/rma_order_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ def _compute_qty_purchase(self):
compute="_compute_qty_purchase",
)

@api.model
def _origin_fields(self):
res = super()._origin_fields()
return res + ["purchase_order_line_id"]

@api.onchange("product_id", "partner_id")
def _onchange_product_id(self):
"""Domain for purchase_order_line_id is computed here to make
Expand Down
5 changes: 5 additions & 0 deletions rma_sale/models/rma_order_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ def _compute_sales_count(self):
)
sales_count = fields.Integer(compute="_compute_sales_count", string="# of Sales")

@api.model
def _origin_fields(self):
res = super()._origin_fields()
return res + ["sale_line_id"]

@api.onchange("product_id", "partner_id")
def _onchange_product_id(self):
"""Domain for sale_line_id is computed here to make it dynamic."""
Expand Down

0 comments on commit 73cc3b6

Please sign in to comment.