Skip to content

Commit

Permalink
[IMP] rma_sale: add replacement product info to rma sale wizard
Browse files Browse the repository at this point in the history
  • Loading branch information
sbejaoui committed Aug 16, 2024
1 parent 31588af commit 387d02c
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 4 deletions.
14 changes: 10 additions & 4 deletions rma/models/rma.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,12 +368,18 @@ def _compute_replace_warehouse_id(self):
[("company_id", "=", rec.company_id.id)], limit=1
)

@api.depends("operation_id.action_create_delivery")
@api.depends(
"operation_id.action_create_delivery", "operation_id.different_return_product"
)
def _compute_show_replacement_fields(self):
for rec in self:
rec.show_replacement_fields = rec.operation_id.action_create_delivery in (
"automatic_on_confirm",
"automatic_after_receipt",
rec.show_replacement_fields = (
rec.operation_id.different_return_product
and rec.operation_id.action_create_delivery
in (
"automatic_on_confirm",
"automatic_after_receipt",
)
)

@api.depends("operation_id.action_create_receipt", "state", "reception_move_id")
Expand Down
64 changes: 64 additions & 0 deletions rma_sale/wizard/sale_order_rma_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,66 @@ class SaleOrderLineRmaWizard(models.TransientModel):
)
description = fields.Text()

# Replace fields, used when the delivery is created automatically
replace_warehouse_id = fields.Many2one(
"stock.warehouse",
help="Warehouse from which the replacement product will be shipped.",
compute="_compute_replace_warehouse_id",
store=True,
readonly=False,
)

replace_product_id = fields.Many2one(
"product.product",
help="Product to be used as the replacement for the returned item.",
)

replace_product_uom_qty = fields.Float(
string="Replacement Quantity",
help="Quantity of the replacement product to be delivered.",
)

replace_product_uom = fields.Many2one(
"uom.uom",
string="Replacement UOM",
help="Unit of Measure for the replacement product.",
default=lambda self: self.env.ref("uom.product_uom_unit").id,
compute="_compute_replace_product_uom",
store=True,
readonly=False,
)
show_replacement_fields = fields.Boolean(compute="_compute_show_replacement_fields")

@api.depends("operation_id")
def _compute_replace_warehouse_id(self):
warehouse_model = self.env["stock.warehouse"]
for rec in self:
rec.replace_warehouse_id = warehouse_model.search(
[("company_id", "=", rec.order_id.company_id.id)], limit=1
)

@api.depends("replace_product_id")
def _compute_replace_product_uom(self):
for record in self:
if record.product_id:
record.replace_product_uom = record.replace_product_id.uom_id

Check warning on line 203 in rma_sale/wizard/sale_order_rma_wizard.py

View check run for this annotation

Codecov / codecov/patch

rma_sale/wizard/sale_order_rma_wizard.py#L203

Added line #L203 was not covered by tests
else:
record.replace_product_uom = False

Check warning on line 205 in rma_sale/wizard/sale_order_rma_wizard.py

View check run for this annotation

Codecov / codecov/patch

rma_sale/wizard/sale_order_rma_wizard.py#L205

Added line #L205 was not covered by tests

@api.depends(
"operation_id.action_create_delivery", "operation_id.different_return_product"
)
def _compute_show_replacement_fields(self):
for rec in self:
rec.show_replacement_fields = (

Check warning on line 212 in rma_sale/wizard/sale_order_rma_wizard.py

View check run for this annotation

Codecov / codecov/patch

rma_sale/wizard/sale_order_rma_wizard.py#L212

Added line #L212 was not covered by tests
rec.operation_id.different_return_product
and rec.operation_id.action_create_delivery
in (
"automatic_on_confirm",
"automatic_after_receipt",
)
)

@api.depends("wizard_id.operation_id")
def _compute_operation_id(self):
for rec in self:
Expand Down Expand Up @@ -223,4 +283,8 @@ def _prepare_rma_values(self):
"product_uom": self.uom_id.id,
"operation_id": self.operation_id.id,
"description": description,
"replace_warehouse_id": self.replace_warehouse_id.id,
"replace_product_id": self.replace_product_id.id,
"replace_product_uom_qty": self.replace_product_uom_qty,
"replace_product_uom": self.replace_product_uom.id,
}
18 changes: 18 additions & 0 deletions rma_sale/wizard/sale_order_rma_wizard_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,24 @@
name="operation_id"
attrs="{'required': [('quantity', '>', 0)]}"
/>
<field
name="replace_warehouse_id"
attrs="{'invisible': [('show_replacement_fields', '=', False)], 'required': [('show_replacement_fields', '=', True)]}"
/>
<field
name="replace_product_id"
attrs="{'invisible': [('show_replacement_fields', '=', False)], 'required': [('show_replacement_fields', '=', True)]}"
/>
<field
name="replace_product_uom_qty"
attrs="{'invisible': [('show_replacement_fields', '=', False)], 'required': [('show_replacement_fields', '=', True)]}"
/>
<field
name="replace_product_uom"
groups="uom.group_uom"
attrs="{'invisible': [('show_replacement_fields', '=', False)], 'required': [('show_replacement_fields', '=', True)]}"
/>
<field name="show_replacement_fields" invisible="1" />
</tree>
</field>
</group>
Expand Down

0 comments on commit 387d02c

Please sign in to comment.