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 28, 2024
1 parent 31588af commit 221d30d
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 16 deletions.
22 changes: 22 additions & 0 deletions rma/migrations/16.0.4.0.0/pre-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright 2024 Tecnativa - Víctor Martínez
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from openupgradelib import openupgrade


@openupgrade.migrate()
def migrate(env, version):
openupgrade.logged_query(
env.cr,
"""
ALTER TABLE rma
ADD COLUMN IF NOT EXISTS replace_warehouse_id INTEGER
""",
)
openupgrade.logged_query(
env.cr,
"""
ALTER TABLE rma
ADD COLUMN IF NOT EXISTS replace_product_uom INTEGER
""",
)
19 changes: 10 additions & 9 deletions rma/models/rma.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,6 @@ def _domain_location_id(self):
readonly=True,
copy=False,
)

show_create_receipt = fields.Boolean(
string="Show Create Receipt Button", compute="_compute_show_create_receipt"
)
Expand All @@ -329,7 +328,6 @@ def _domain_location_id(self):
show_create_refund = fields.Boolean(
string="Show Create refund Button", compute="_compute_show_refund_replace"
)

# Replace fields, used when the delivery is created automatically
replace_warehouse_id = fields.Many2one(
"stock.warehouse",
Expand All @@ -338,17 +336,14 @@ def _domain_location_id(self):
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",
Expand All @@ -368,12 +363,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
11 changes: 4 additions & 7 deletions rma/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@

/*
:Author: David Goodger ([email protected])
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
:Copyright: This stylesheet has been placed in the public domain.

Default cascading style sheet for the HTML output of Docutils.
Despite the name, some widely supported CSS2 features are used.

See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
customize this style sheet.
Expand Down Expand Up @@ -275,7 +274,7 @@
margin-left: 2em ;
margin-right: 2em }

pre.code .ln { color: gray; } /* line numbers */
pre.code .ln { color: grey; } /* line numbers */
pre.code, code { background-color: #eeeeee }
pre.code .comment, code .comment { color: #5C6576 }
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
Expand All @@ -301,7 +300,7 @@
span.pre {
white-space: pre }

span.problematic, pre.problematic {
span.problematic {
color: red }

span.section-subtitle {
Expand Down Expand Up @@ -530,9 +529,7 @@ <h2><a class="toc-backref" href="#toc-entry-7">Contributors</a></h2>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-8">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
</a>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.</p>
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 221d30d

Please sign in to comment.