-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #568 from ForgeFlow/17.0-mig-rma_reason_code
[17.0] [MIG] rma_reason_code
- Loading branch information
Showing
21 changed files
with
1,086 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
=============== | ||
RMA Reason Code | ||
=============== | ||
|
||
.. | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! source digest: sha256:7fe458ca9d7af3377506c22b519e03a0a8175169e7939409a36821718e03392a | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png | ||
:target: https://odoo-community.org/page/development-status | ||
:alt: Beta | ||
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png | ||
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html | ||
:alt: License: AGPL-3 | ||
.. |badge3| image:: https://img.shields.io/badge/github-ForgeFlow%2Fstock--rma-lightgray.png?logo=github | ||
:target: https://github.com/ForgeFlow/stock-rma/tree/17.0/rma_reason_code | ||
:alt: ForgeFlow/stock-rma | ||
|
||
|badge1| |badge2| |badge3| | ||
|
||
Adds a reason code for RMA operations and an interface for the user to | ||
create RMA codes | ||
|
||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues <https://github.com/ForgeFlow/stock-rma/issues>`_. | ||
In case of trouble, please check there if your issue has already been reported. | ||
If you spotted it first, help us to smash it by providing a detailed and welcomed | ||
`feedback <https://github.com/ForgeFlow/stock-rma/issues/new?body=module:%20rma_reason_code%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. | ||
|
||
Do not contact contributors directly about support or help with technical issues. | ||
|
||
Credits | ||
======= | ||
|
||
Authors | ||
------- | ||
|
||
* ForgeFlow | ||
|
||
Contributors | ||
------------ | ||
|
||
- David Jiménez <[email protected]> | ||
|
||
Maintainers | ||
----------- | ||
|
||
This module is part of the `ForgeFlow/stock-rma <https://github.com/ForgeFlow/stock-rma/tree/17.0/rma_reason_code>`_ project on GitHub. | ||
|
||
You are welcome to contribute. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Copyright 2024 ForgeFlow S.L. (https://www.forgeflow.com) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
from . import models | ||
from . import reports |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Copyright 2024 ForgeFlow S.L. (https://www.forgeflow.com) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
{ | ||
"name": "RMA Reason Code", | ||
"version": "17.0.1.0.0", | ||
"license": "AGPL-3", | ||
"summary": "Reason code for RMA", | ||
"author": "ForgeFlow", | ||
"website": "https://github.com/ForgeFlow", | ||
"category": "Warehouse Management", | ||
"depends": ["rma"], | ||
"data": [ | ||
"security/ir.model.access.csv", | ||
"security/security.xml", | ||
"views/reason_code_view.xml", | ||
"views/rma_order_line_views.xml", | ||
"reports/rma_reason_code_report_views.xml", | ||
], | ||
"installable": True, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
"rma_type", | ||
) | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Copyright 2024 ForgeFlow S.L. (https://www.forgeflow.com) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
from . import reason_code | ||
from . import rma_order_line |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Copyright 2024 ForgeFlow S.L. (https://www.forgeflow.com) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
from random import randint | ||
|
||
from odoo import fields, models | ||
|
||
|
||
class RMAReasonCode(models.Model): | ||
_name = "rma.reason.code" | ||
_description = "RMA Reason Code" | ||
|
||
def _get_default_color(self): | ||
return randint(1, 11) | ||
|
||
name = fields.Char("Code", required=True) | ||
description = fields.Text() | ||
rma_type = fields.Selection( | ||
[ | ||
("customer", "Customer RMA"), | ||
("supplier", "Supplier RTV"), | ||
("both", "Both Customer and Supplier"), | ||
], | ||
default="both", | ||
string="RMA Type", | ||
required=True, | ||
) | ||
color = fields.Integer(default=_get_default_color) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# Copyright 2024 ForgeFlow S.L. (https://www.forgeflow.com) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import _, api, fields, models | ||
from odoo.exceptions import ValidationError | ||
|
||
|
||
class RMAOrderLine(models.Model): | ||
_inherit = "rma.order.line" | ||
|
||
reason_code_ids = fields.Many2many( | ||
"rma.reason.code", | ||
"rma_order_line_reason_code_rel", | ||
string="Reason Code", | ||
domain="[('id', 'in', allowed_reason_code_ids)]", | ||
) | ||
allowed_reason_code_ids = fields.Many2many( | ||
comodel_name="rma.reason.code", | ||
compute="_compute_allowed_reason_code_ids", | ||
) | ||
|
||
@api.depends("type") | ||
def _compute_allowed_reason_code_ids(self): | ||
for rec in self: | ||
codes = self.env["rma.reason.code"] | ||
if rec.type == "customer": | ||
codes = codes.search([("rma_type", "in", ["customer", "both"])]) | ||
else: | ||
codes = codes.search([("rma_type", "in", ["supplier", "both"])]) | ||
rec.allowed_reason_code_ids = codes | ||
|
||
@api.constrains("reason_code_ids", "product_id") | ||
def _check_reason_code_ids(self): | ||
for rec in self: | ||
if rec.reason_code_ids and not any( | ||
rc in rec.allowed_reason_code_ids for rc in rec.reason_code_ids | ||
): | ||
raise ValidationError( | ||
_( | ||
"Any of the reason code selected is not allowed for " | ||
"this type of RMA (%s)." | ||
) | ||
% rec.type | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[build-system] | ||
requires = ["whool"] | ||
build-backend = "whool.buildapi" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
- David Jiménez \<<[email protected]>\> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Adds a reason code for RMA operations and an interface for the user to | ||
create RMA codes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import rma_reason_code_report |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# Copyright 2022 ForgeFlow S.L. | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). | ||
|
||
from odoo import fields, models | ||
|
||
|
||
class RmaReasonCodeReport(models.Model): | ||
_name = "rma.reason.code.report" | ||
_auto = False | ||
_description = "Rma Reason Code Report" | ||
|
||
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") | ||
rma_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 AS rma_type, | ||
rrc.id as reason_code_id, | ||
rma.date_rma, | ||
rma.company_id | ||
""" | ||
|
||
def _from(self): | ||
return """ | ||
FROM | ||
rma_order_line rma | ||
INNER JOIN | ||
rma_order_line_reason_code_rel rolr | ||
ON rma.id = rolr.rma_order_line_id | ||
INNER JOIN | ||
rma_reason_code rrc ON rolr.rma_reason_code_id = rrc.id | ||
""" | ||
|
||
def _order_by(self): | ||
return """ | ||
ORDER BY | ||
rma.id, rrc.id | ||
""" | ||
|
||
@property | ||
def _table_query(self): | ||
return f""" | ||
{self._select()} | ||
{self._from()} | ||
{self._order_by()} | ||
""" |
122 changes: 122 additions & 0 deletions
122
rma_reason_code/reports/rma_reason_code_report_views.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<odoo> | ||
<record id="rma_reason_code_report_tree_view" model="ir.ui.view"> | ||
<field name="name">rma.reason.code.report.tree</field> | ||
<field name="model">rma.reason.code.report</field> | ||
<field name="arch" type="xml"> | ||
<tree> | ||
<field name="rma_order_line_id" /> | ||
<field name="reason_code_id" /> | ||
<field name="date_rma" optional="show" /> | ||
<field name="rma_type" optional="hide" /> | ||
<field name="company_id" optional="hide" /> | ||
</tree> | ||
</field> | ||
</record> | ||
|
||
<record id="rma_reason_code_report_graph_view" model="ir.ui.view"> | ||
<field name="name">rma.reason.code.report.graph</field> | ||
<field name="model">rma.reason.code.report</field> | ||
<field name="arch" type="xml"> | ||
<graph type="bar" sample="1"> | ||
<field name="date_rma" interval="week" /> | ||
</graph> | ||
</field> | ||
</record> | ||
|
||
<record id="rma_reason_code_report_search_view" model="ir.ui.view"> | ||
<field name="name">rma.reason.code.report.search</field> | ||
<field name="model">rma.reason.code.report</field> | ||
<field name="arch" type="xml"> | ||
<search> | ||
<field name="reason_code_id" /> | ||
<group name="rma_type"> | ||
<separator /> | ||
<filter | ||
name="is_customer" | ||
string="Customer" | ||
domain="[('rma_type', '=', 'customer')]" | ||
/> | ||
<filter | ||
name="is_supplier" | ||
string="Supplier" | ||
domain="[('rma_type', '=', 'supplier')]" | ||
/> | ||
</group> | ||
<separator /> | ||
<separator /> | ||
<filter name="date_rma" string="Date" date="date_rma" /> | ||
<filter | ||
name="group_rma_date" | ||
string="RMA Date" | ||
context="{'group_by':'date_rma:week'}" | ||
/> | ||
<filter | ||
name="group_reason_code_id" | ||
string="Reason Code" | ||
context="{'group_by':'reason_code_id'}" | ||
/> | ||
</search> | ||
</field> | ||
</record> | ||
|
||
|
||
<record id="action_rma_reason_code_report" model="ir.actions.act_window"> | ||
<field name="name">RMA Reason Code Analysis</field> | ||
<field name="res_model">rma.reason.code.report</field> | ||
<field name="view_mode">graph,pivot,tree</field> | ||
<field | ||
name="search_view_id" | ||
ref="rma_reason_code.rma_reason_code_report_search_view" | ||
/> | ||
<field name="context">{ | ||
'search_default_group_rma_date': 1, | ||
'search_default_group_reason_code_id': 2, | ||
'search_default_is_customer': 1, | ||
}</field> | ||
<field name="help" type="html"> | ||
<p class="o_view_nocontent_smiling_face"> | ||
No data yet! | ||
</p><p> | ||
Assign a Reason Code to a RMA | ||
</p> | ||
</field> | ||
</record> | ||
|
||
<record id="action_rtv_reason_code_report" model="ir.actions.act_window"> | ||
<field name="name">RTV Reason Code Analysis</field> | ||
<field name="res_model">rma.reason.code.report</field> | ||
<field name="view_mode">graph,pivot,tree</field> | ||
<field | ||
name="search_view_id" | ||
ref="rma_reason_code.rma_reason_code_report_search_view" | ||
/> | ||
<field name="context">{ | ||
'search_default_group_rma_date': 1, | ||
'search_default_group_reason_code_id': 2, | ||
'search_default_is_supplier': 1, | ||
}</field> | ||
<field name="help" type="html"> | ||
<p class="o_view_nocontent_smiling_face"> | ||
No data yet! | ||
</p><p> | ||
Assign a Reason Code to a RTV | ||
</p> | ||
</field> | ||
</record> | ||
|
||
<menuitem | ||
action="action_rma_reason_code_report" | ||
id="menu_rma_reason_code_report" | ||
parent="rma.menu_rma_rma_report" | ||
sequence="140" | ||
/> | ||
|
||
<menuitem | ||
action="action_rtv_reason_code_report" | ||
id="menu_rtv_reason_code_report" | ||
parent="rma.menu_rma_rma_report" | ||
sequence="141" | ||
/> | ||
|
||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink | ||
access_rma_reason_code_user,rma.reason.code,model_rma_reason_code,rma.group_rma_customer_user,1,0,0,0 | ||
access_rma_reason_code_manager,rma.reason.code,model_rma_reason_code,rma.group_rma_manager,1,1,1,1 | ||
access_rma_reason_code_report_user,rma.reason.code.report,model_rma_reason_code_report,rma.group_rma_customer_user,1,0,0,0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<!-- | ||
Copyright 2024 ForgeFlow S.L. (https://www.forgeflow.com) | ||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
--> | ||
<odoo> | ||
<record id="rma_reason_code_report_comp_rule" model="ir.rule"> | ||
<field name="name">RMA Reason Code Report</field> | ||
<field name="model_id" ref="model_rma_reason_code_report" /> | ||
<field | ||
name="domain_force" | ||
>['|',('company_id','=',False),('company_id', 'in', company_ids)]</field> | ||
</record> | ||
</odoo> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.