Skip to content

Commit

Permalink
[MIG] rma_reason_code: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
MeritxellAForgeFlow committed Dec 18, 2024
1 parent d1d42fb commit b17baa8
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 23 deletions.
2 changes: 1 addition & 1 deletion rma_reason_code/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "RMA Reason Code",
"version": "14.0.1.1.0",
"version": "17.0.1.0.0",
"license": "AGPL-3",
"summary": "Reason code for RMA",
"author": "ForgeFlow",
Expand Down
17 changes: 17 additions & 0 deletions rma_reason_code/migrations/17.0.1.0.0/pre-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from openupgradelib import openupgrade


@openupgrade.migrate()
def migrate(env, version):
if openupgrade.column_exists(env.cr, "rma_reason_code", "type"):
openupgrade.rename_fields(
env,
[
(
"rma.reason.code",
"rma_reason_code",
"type",
"item_type",
)
],
)
6 changes: 3 additions & 3 deletions rma_reason_code/models/reason_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ def _get_default_color(self):
return randint(1, 11)

name = fields.Char("Code", required=True)
description = fields.Text("Description")
type = fields.Selection(
description = fields.Text()
item_type = fields.Selection(
[
("customer", "Customer RMA"),
("supplier", "Supplier RTV"),
Expand All @@ -23,4 +23,4 @@ def _get_default_color(self):
default="both",
required=True,
)
color = fields.Integer("Color", default=_get_default_color)
color = fields.Integer(default=_get_default_color)
4 changes: 2 additions & 2 deletions rma_reason_code/models/rma_order_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ def _compute_allowed_reason_code_ids(self):
for rec in self:
codes = self.env["rma.reason.code"]
if rec.type == "customer":
codes = codes.search([("type", "in", ["customer", "both"])])
codes = codes.search([("item_type", "in", ["customer", "both"])])
else:
codes = codes.search([("type", "in", ["supplier", "both"])])
codes = codes.search([("item_type", "in", ["supplier", "both"])])
rec.allowed_reason_code_ids = codes

@api.constrains("reason_code_ids", "product_id")
Expand Down
4 changes: 2 additions & 2 deletions rma_reason_code/reports/rma_reason_code_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ class RmaReasonCodeReport(models.Model):
rma_order_line_id = fields.Many2one(comodel_name="rma.order.line")
reason_code_id = fields.Many2one(comodel_name="rma.reason.code")
date_rma = fields.Datetime(string="Order Date")
type = fields.Selection([("customer", "Customer"), ("supplier", "Supplier")])
item_type = fields.Selection([("customer", "Customer"), ("supplier", "Supplier")])
company_id = fields.Many2one(comodel_name="res.company")

def _select(self):
return """
SELECT
row_number() OVER () AS id,
rma.id as rma_order_line_id,
rma.type,
rma.type AS item_type,
rrc.id as reason_code_id,
rma.date_rma,
rma.company_id
Expand Down
6 changes: 3 additions & 3 deletions rma_reason_code/reports/rma_reason_code_report_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<field name="rma_order_line_id" />
<field name="reason_code_id" />
<field name="date_rma" optional="show" />
<field name="type" optional="hide" />
<field name="item_type" optional="hide" />
<field name="company_id" optional="hide" />
</tree>
</field>
Expand All @@ -35,12 +35,12 @@
<filter
name="is_customer"
string="Customer"
domain="[('type', '=', 'customer')]"
domain="[('item_type', '=', 'customer')]"
/>
<filter
name="is_supplier"
string="Supplier"
domain="[('type', '=', 'supplier')]"
domain="[('item_type', '=', 'supplier')]"
/>
</group>
<separator />
Expand Down
8 changes: 4 additions & 4 deletions rma_reason_code/tests/test_scrap_reason_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from odoo.tests import common


class RMAOrderLine(common.SavepointCase):
class RMAOrderLine(common.TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
Expand Down Expand Up @@ -105,21 +105,21 @@ def setUpClass(cls):
{
"name": "Test Code 1",
"description": "Test description",
"type": "both",
"item_type": "both",
}
)
cls.reason_code_customer = cls.env["rma.reason.code"].create(
{
"name": "Test Code 2",
"description": "Test description",
"type": "customer",
"item_type": "customer",
}
)
cls.reason_code_supplier = cls.env["rma.reason.code"].create(
{
"name": "Test Code 3",
"description": "Test description",
"type": "supplier",
"item_type": "supplier",
}
)

Expand Down
6 changes: 3 additions & 3 deletions rma_reason_code/views/reason_code_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
nolabel="1"
colspan="2"
/>
<field name="type" />
<field name="item_type" />
<field name="color" widget="color_picker" />
</group>
</sheet>
Expand All @@ -32,10 +32,10 @@
<field name="name">rma.reason.code.list</field>
<field name="model">rma.reason.code</field>
<field name="arch" type="xml">
<tree string="Reason Codes">
<tree>
<field name="name" />
<field name="description" />
<field name="type" />
<field name="item_type" />
<field name="color" widget="color_picker" />
</tree>
</field>
Expand Down
10 changes: 5 additions & 5 deletions rma_reason_code/views/rma_order_line_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
widget="many2many_tags"
options="{'color_field': 'color', 'no_create': True}"
/>
<field name="allowed_reason_code_ids" invisible="1" />
<field name="allowed_reason_code_ids" column_invisible="1" />
</field>
</field>
</record>
Expand All @@ -32,7 +32,7 @@
widget="many2many_tags"
options="{'color_field': 'color', 'no_create': True}"
/>
<field name="allowed_reason_code_ids" invisible="1" />
<field name="allowed_reason_code_ids" column_invisible="1" />
</field>
</field>
</record>
Expand All @@ -48,7 +48,7 @@
widget="many2many_tags"
options="{'color_field': 'color', 'no_create': True}"
/>
<field name="allowed_reason_code_ids" invisible="1" />
<field name="allowed_reason_code_ids" column_invisible="1" />
</field>
</field>
</record>
Expand All @@ -66,8 +66,8 @@
string="Reason Code"
context="{'group_by':'reason_code_ids'}"
/>
<field name="allowed_reason_code_ids" invisible="1" />
<field name="allowed_reason_code_ids" invisible="1" />
<field name="allowed_reason_code_ids" column_invisible="1" />
<field name="allowed_reason_code_ids" column_invisible="1" />
</filter>
</field>
</record>
Expand Down

0 comments on commit b17baa8

Please sign in to comment.