Skip to content

Commit

Permalink
[ADD] rma_reason_code
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidJForgeFlow committed Jul 8, 2024
1 parent 0062a8d commit 2d504e4
Show file tree
Hide file tree
Showing 21 changed files with 1,052 additions and 0 deletions.
47 changes: 47 additions & 0 deletions rma_reason_code/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:alt: License LGPL-3

============
RMA Put Away
============

This module allows you to put away the products after you have received them.

Configuration
=============

Go to *RMA / Configuration / Customer Operations* and define there:

#. The Put Away Policy
#. The route that you wish to use to put away the products.
#. The default destination location (optional).

Usage
=====

#. Go to a Customer RMA.
#. Click on *Put Away*.
#. Indicate the quantity that you want to put away and destination location.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues
<https://github.com/Eficent/stock-rma/issues>`_. In case of trouble, please
check there if your issue has already been reported. If you spotted it first,
help us smashing it by providing a detailed and welcomed feedback.

Credits
=======

Contributors
------------

* Jordi Ballester Alomar <jordi.ballester@ForgeFlow.com>
* David Jimenez <david.jimenez@ForgeFlow.com>


Maintainer
----------

This module is maintained by ForgeFlow
4 changes: 4 additions & 0 deletions rma_reason_code/__init__.py
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
20 changes: 20 additions & 0 deletions rma_reason_code/__manifest__.py
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": "14.0.1.1.0",
"license": "AGPL-3",
"summary": "Reason code for RMA",
"author": "ForgeFlow",
"website": "https://github.com/ForgeFlow/stock-rma",
"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,
}
4 changes: 4 additions & 0 deletions rma_reason_code/models/__init__.py
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
22 changes: 22 additions & 0 deletions rma_reason_code/models/reason_code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright 2024 ForgeFlow S.L. (https://www.forgeflow.com)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import fields, models


class RMAReasonCode(models.Model):
_name = "rma.reason.code"
_description = "RMA Reason Code"

name = fields.Char("Code", required=True)
description = fields.Text("Description")
type = fields.Selection(
[
("customer", "Customer RMA"),
("supplier", "Supplier RTV"),
("both", "Both Customer and Supplier"),
],
default="both",
required=True,
)
color = fields.Char(string="Color", help="The color of the reason code")
44 changes: 44 additions & 0 deletions rma_reason_code/models/rma_order_line.py
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([("type", "in", ["customer", "both"])])
else:
codes = codes.search([("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
)
1 change: 1 addition & 0 deletions rma_reason_code/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* David Jiménez <david.jimenez@forgeflow.com>
1 change: 1 addition & 0 deletions rma_reason_code/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Adds a reason code for RMA operations and an interface for the user to create RMA codes
1 change: 1 addition & 0 deletions rma_reason_code/reports/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import rma_reason_code_report
55 changes: 55 additions & 0 deletions rma_reason_code/reports/rma_reason_code_report.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# 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")
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,
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 """
{_select}
{_from}
{_order_by}
""".format(
_select=self._select(), _from=self._from(), _order_by=self._order_by()
)
90 changes: 90 additions & 0 deletions rma_reason_code/reports/rma_reason_code_report_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?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="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="[('type', '=', 'customer')]"
/>
<filter
name="is_supplier"
string="Supplier"
domain="[('type', '=', 'supplier')]"
/>
</group>
<separator />
<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,
}</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>

<menuitem
action="action_rma_reason_code_report"
id="menu_rma_reason_code_report"
parent="rma.menu_rma_rma_report"
sequence="140"
/>

</odoo>
4 changes: 4 additions & 0 deletions rma_reason_code/security/ir.model.access.csv
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
14 changes: 14 additions & 0 deletions rma_reason_code/security/security.xml
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>
Binary file added rma_reason_code/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 2d504e4

Please sign in to comment.