Skip to content

Commit

Permalink
[IMP] rma_reason: filter operation by reason
Browse files Browse the repository at this point in the history
  • Loading branch information
sbejaoui committed Aug 18, 2024
1 parent 9a3a65b commit 618c595
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 4 deletions.
13 changes: 12 additions & 1 deletion rma_reason/models/rma.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Copyright 2024 ACSONE SA/NV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields, models
from odoo import api, fields, models


class Rma(models.Model):
Expand All @@ -12,3 +12,14 @@ class Rma(models.Model):

reason_id = fields.Many2one(comodel_name="rma.reason")
is_rma_reason_required = fields.Boolean(related="company_id.is_rma_reason_required")
operation_domain = fields.Binary(compute="_compute_operation_domain")

@api.depends("reason_id")
def _compute_operation_domain(self):
for rec in self:
if rec.reason_id and rec.reason_id.allowed_operation_ids:
rec.operation_domain = [

Check warning on line 21 in rma_reason/models/rma.py

View check run for this annotation

Codecov / codecov/patch

rma_reason/models/rma.py#L21

Added line #L21 was not covered by tests
("id", "in", rec.reason_id.allowed_operation_ids.ids)
]
else:
rec.operation_domain = []

Check warning on line 25 in rma_reason/models/rma.py

View check run for this annotation

Codecov / codecov/patch

rma_reason/models/rma.py#L25

Added line #L25 was not covered by tests
5 changes: 5 additions & 0 deletions rma_reason/models/rma_reason.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,8 @@ class RmaReason(models.Model):
readonly=True,
default=lambda self: self.env.company,
)
allowed_operation_ids = fields.Many2many(
comodel_name="rma.operation",
string="Operations",
help="List of RMA operations that are allowed when this reason is selected.",
)
8 changes: 7 additions & 1 deletion rma_reason/views/rma.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,19 @@
<field name="model">rma</field>
<field name="inherit_id" ref="rma.rma_view_form" />
<field name="arch" type="xml">
<xpath expr="//field[@name='operation_id']" position="after">
<xpath expr="//field[@name='operation_id']" position="before">
<field name="is_rma_reason_required" invisible="True" />
<field
name="reason_id"
attrs="{'required': [('is_rma_reason_required', '=', True)]}"
/>
</xpath>
<xpath expr="//field[@name='operation_id']" position="after">
<field name="operation_domain" invisible="1" />
</xpath>
<xpath expr="//field[@name='operation_id']" position="attributes">
<attribute name="domain">operation_domain</attribute>
</xpath>
</field>
</record>

Expand Down
1 change: 1 addition & 0 deletions rma_reason/views/rma_reason.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<field name="name" />
<field name="company_id" groups="base.group_multi_company" />
<field name="description" />
<field name="allowed_operation_ids" widget="many2many_tags" />
</group>
</sheet>
</form>
Expand Down
13 changes: 12 additions & 1 deletion rma_reason/wizards/stock_return_picking.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright 2024 ACSONE SA/NV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields, models
from odoo import api, fields, models


class StockReturnPicking(models.TransientModel):
Expand All @@ -11,3 +11,14 @@ class StockReturnPicking(models.TransientModel):
rma_reason_id = fields.Many2one(
comodel_name="rma.reason", readonly=False, string="RMA Reason"
)
rma_operation_domain = fields.Binary(compute="_compute_rma_operation_domain")

@api.depends("rma_reason_id")
def _compute_rma_operation_domain(self):
for rec in self:
if rec.rma_reason_id and rec.rma_reason_id.allowed_operation_ids:
rec.rma_operation_domain = [

Check warning on line 20 in rma_reason/wizards/stock_return_picking.py

View check run for this annotation

Codecov / codecov/patch

rma_reason/wizards/stock_return_picking.py#L20

Added line #L20 was not covered by tests
("id", "in", rec.rma_reason_id.allowed_operation_ids.ids)
]
else:
rec.rma_operation_domain = []

Check warning on line 24 in rma_reason/wizards/stock_return_picking.py

View check run for this annotation

Codecov / codecov/patch

rma_reason/wizards/stock_return_picking.py#L24

Added line #L24 was not covered by tests
15 changes: 15 additions & 0 deletions rma_reason/wizards/stock_return_picking.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@
attrs="{'column_invisible': [('parent.create_rma', '=', False)], 'required': [('is_rma_reason_required', '=', True), ('parent.create_rma', '=', True), ('quantity', '>', 0)]}"
/>
<field name="is_rma_reason_required" invisible="1" />
<field name="rma_operation_domain" invisible="1" />
</xpath>
<xpath
expr="//field[@name='product_return_moves']//tree//field[@name='rma_operation_id']"
position="attributes"
>
<attribute name="domain">rma_operation_domain</attribute>
</xpath>
<xpath
expr="//group[@name='group_rma']//field[@name='rma_operation_id']"
Expand All @@ -25,7 +32,15 @@
name="rma_reason_id"
attrs="{'invisible': [('create_rma', '=', False)]}"
/>
<field name="rma_operation_domain" invisible="1" />
</xpath>
<xpath
expr="//group[@name='group_rma']//field[@name='rma_operation_id']"
position="attributes"
>
<attribute name="domain">rma_operation_domain</attribute>
</xpath>

</field>
</record>

Expand Down
11 changes: 11 additions & 0 deletions rma_reason/wizards/stock_return_picking_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class StockReturnPickingLine(models.TransientModel):
is_rma_reason_required = fields.Boolean(
related="wizard_id.company_id.is_rma_reason_required"
)
rma_operation_domain = fields.Binary(compute="_compute_rma_operation_domain")

@api.depends("wizard_id.rma_reason_id")
def _compute_rma_reason_id(self):
Expand All @@ -30,3 +31,13 @@ def _prepare_rma_vals(self):
vals = super()._prepare_rma_vals()
vals["reason_id"] = self.rma_reason_id.id
return vals

Check warning on line 33 in rma_reason/wizards/stock_return_picking_line.py

View check run for this annotation

Codecov / codecov/patch

rma_reason/wizards/stock_return_picking_line.py#L30-L33

Added lines #L30 - L33 were not covered by tests

@api.depends("rma_reason_id")
def _compute_rma_operation_domain(self):
for rec in self:
if rec.rma_reason_id and rec.rma_reason_id.allowed_operation_ids:
rec.rma_operation_domain = [

Check warning on line 39 in rma_reason/wizards/stock_return_picking_line.py

View check run for this annotation

Codecov / codecov/patch

rma_reason/wizards/stock_return_picking_line.py#L39

Added line #L39 was not covered by tests
("id", "in", rec.rma_reason_id.allowed_operation_ids.ids)
]
else:
rec.rma_operation_domain = []

Check warning on line 43 in rma_reason/wizards/stock_return_picking_line.py

View check run for this annotation

Codecov / codecov/patch

rma_reason/wizards/stock_return_picking_line.py#L43

Added line #L43 was not covered by tests
11 changes: 11 additions & 0 deletions rma_sale_reason/wizards/sale_order_line_rma_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ class SaleOrderLineRmaWizard(models.TransientModel):
is_rma_reason_required = fields.Boolean(
related="order_id.company_id.is_rma_reason_required"
)
operation_domain = fields.Binary(compute="_compute_operation_domain")

@api.depends("reason_id")
def _compute_operation_domain(self):
for rec in self:
if rec.reason_id and rec.reason_id.allowed_operation_ids:
rec.operation_domain = [

Check warning on line 28 in rma_sale_reason/wizards/sale_order_line_rma_wizard.py

View check run for this annotation

Codecov / codecov/patch

rma_sale_reason/wizards/sale_order_line_rma_wizard.py#L28

Added line #L28 was not covered by tests
("id", "in", rec.reason_id.allowed_operation_ids.ids)
]
else:
rec.operation_domain = []

Check warning on line 32 in rma_sale_reason/wizards/sale_order_line_rma_wizard.py

View check run for this annotation

Codecov / codecov/patch

rma_sale_reason/wizards/sale_order_line_rma_wizard.py#L32

Added line #L32 was not covered by tests

@api.depends("wizard_id.reason_id")
def _compute_reason_id(self):
Expand Down
13 changes: 12 additions & 1 deletion rma_sale_reason/wizards/sale_order_rma_wizard.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
# Copyright 2024 ACSONE SA/NV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields, models
from odoo import api, fields, models


class SaleOrderRmaWizard(models.TransientModel):

_inherit = "sale.order.rma.wizard"

reason_id = fields.Many2one(comodel_name="rma.reason")
operation_domain = fields.Binary(compute="_compute_operation_domain")

@api.depends("reason_id")
def _compute_operation_domain(self):
for rec in self:
if rec.reason_id and rec.reason_id.allowed_operation_ids:
rec.operation_domain = [

Check warning on line 18 in rma_sale_reason/wizards/sale_order_rma_wizard.py

View check run for this annotation

Codecov / codecov/patch

rma_sale_reason/wizards/sale_order_rma_wizard.py#L18

Added line #L18 was not covered by tests
("id", "in", rec.reason_id.allowed_operation_ids.ids)
]
else:
rec.operation_domain = []

Check warning on line 22 in rma_sale_reason/wizards/sale_order_rma_wizard.py

View check run for this annotation

Codecov / codecov/patch

rma_sale_reason/wizards/sale_order_rma_wizard.py#L22

Added line #L22 was not covered by tests
11 changes: 11 additions & 0 deletions rma_sale_reason/wizards/sale_order_rma_wizard.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,28 @@
<field name="arch" type="xml">
<xpath expr="//field[@name='operation_id']" position="before">
<field name="reason_id" />
<field name="operation_domain" invisible="1" />
</xpath>
<xpath expr="//field[@name='operation_id']" position="attributes">
<attribute name="domain">operation_domain</attribute>
</xpath>
<xpath
expr="//field[@name='line_ids']//field[@name='operation_id']"
position="before"
>
<field name="is_rma_reason_required" invisible="True" />
<field name="operation_domain" invisible="1" />
<field
name="reason_id"
attrs="{'required': [('is_rma_reason_required', '=', True), ('quantity', '>', 0)]}"
/>
</xpath>
<xpath
expr="//field[@name='line_ids']//field[@name='operation_id']"
position="attributes"
>
<attribute name="domain">operation_domain</attribute>
</xpath>
</field>
</record>

Expand Down

0 comments on commit 618c595

Please sign in to comment.