diff --git a/rma_invoice/README.rst b/rma_invoice/README.rst new file mode 100644 index 00000000..242375e6 --- /dev/null +++ b/rma_invoice/README.rst @@ -0,0 +1,81 @@ +==================== +RMA Invoices Related +==================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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-LGPL--3-blue.png + :target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html + :alt: License: LGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Frma-lightgray.png?logo=github + :target: https://github.com/OCA/rma/tree/14.0/rma_invoice + :alt: OCA/rma +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/rma-14-0/rma-14-0-rma_invoice + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/145/14.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module add possibility to create invoice for extra services on RMA creation + +**Table of contents** + +.. contents:: + :local: + +Bug Tracker +=========== + +Bugs are tracked on `GitHub 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 `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* ForgeFlow + +Contributors +~~~~~~~~~~~~ + +* Christopher Ormaza + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +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. + +.. |maintainer-ChisOForgeFlow| image:: https://github.com/ChisOForgeFlow.png?size=40px + :target: https://github.com/ChisOForgeFlow + :alt: ChisOForgeFlow + +Current `maintainer `__: + +|maintainer-ChisOForgeFlow| + +This module is part of the `OCA/rma `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/rma_invoice/__init__.py b/rma_invoice/__init__.py new file mode 100644 index 00000000..9b429614 --- /dev/null +++ b/rma_invoice/__init__.py @@ -0,0 +1,2 @@ +from . import models +from . import wizard diff --git a/rma_invoice/__manifest__.py b/rma_invoice/__manifest__.py new file mode 100644 index 00000000..34a17652 --- /dev/null +++ b/rma_invoice/__manifest__.py @@ -0,0 +1,23 @@ +# © 2022 ForgeFlow S.L. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) + +{ + "name": "RMA Invoices Related", + "version": "14.0.1.0.0", + "category": "RMA", + "summary": "RMA Invoices Related", + "license": "LGPL-3", + "author": "ForgeFlow, Odoo Community Association (OCA)", + "website": "https://github.com/ForgeFlow/stock-rma", + "depends": ["rma", "rma_account", "purchase"], + "data": [ + "security/ir.model.access.csv", + "wizard/wizard_create_invoice_rma_view.xml", + "views/account_move_view.xml", + "views/rma_order_line_view.xml", + "views/rma_operation_view.xml", + ], + "maintainers": ["ChisOForgeFlow"], + "development_status": "Beta", + "installable": True, +} diff --git a/rma_invoice/models/__init__.py b/rma_invoice/models/__init__.py new file mode 100644 index 00000000..aa86a5b6 --- /dev/null +++ b/rma_invoice/models/__init__.py @@ -0,0 +1,3 @@ +from . import account_move +from . import rma_order_line +from . import rma_operation diff --git a/rma_invoice/models/account_move.py b/rma_invoice/models/account_move.py new file mode 100644 index 00000000..6ed0f3ed --- /dev/null +++ b/rma_invoice/models/account_move.py @@ -0,0 +1,52 @@ +# Copyright 2022 ForgeFlow S.L. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) +from odoo import api, fields, models +from odoo.tools.safe_eval import safe_eval + + +class AccountMove(models.Model): + + _inherit = "account.move" + + rma_order_line_ids = fields.Many2many( + comodel_name="rma.order.line", string="Rma orders" + ) + + rma_order_line_count = fields.Integer( + string="Rma order lines Count", + compute="_compute_rma_order_line_count", + ) + + @api.depends("rma_order_line_ids") + def _compute_rma_order_line_count(self): + for rec in self: + rec.rma_order_line_count = len(rec.rma_order_line_ids) + + def action_show_rma_lines(self): + self.ensure_one() + action = {} + form_view = False + if self.move_type == "out_invoice": + action = self.env["ir.actions.actions"]._for_xml_id( + "rma.action_rma_customer_lines" + ) + form_view = [(self.env.ref("rma.view_rma_line_form").id, "form")] + elif self.move_type == "in_invoice": + action = self.env["ir.actions.actions"]._for_xml_id( + "rma.action_rma_supplier_lines" + ) + form_view = [(self.env.ref("rma.view_rma_line_supplier_form").id, "form")] + if len(self.rma_order_line_ids) <= 1 and form_view: + if "views" in action: + action["views"] = form_view + [ + (state, view) for state, view in action["views"] if view != "form" + ] + else: + action["views"] = form_view + action["res_id"] = self.rma_order_line_ids.ids[0] + else: + action["domain"] += [("id", "in", self.rma_order_line_ids.ids)] + domain = safe_eval(action["domain"]) or [] + domain += [("id", "in", self.rma_order_line_ids.ids)] + action["domain"] = action["domain"] + return action diff --git a/rma_invoice/models/rma_operation.py b/rma_invoice/models/rma_operation.py new file mode 100644 index 00000000..adcf1f8c --- /dev/null +++ b/rma_invoice/models/rma_operation.py @@ -0,0 +1,18 @@ +# Copyright 2022 ForgeFlow S.L. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) +from odoo import fields, models + + +class RmaOperation(models.Model): + + _inherit = "rma.operation" + + invoice_policy = fields.Selection( + string="Invoice policy", + selection=[ + ("no", "Can't Create Services Invoice"), + ("yes", "Can Create Services Invoice"), + ], + required=False, + default="no", + ) diff --git a/rma_invoice/models/rma_order_line.py b/rma_invoice/models/rma_order_line.py new file mode 100644 index 00000000..ef5227f2 --- /dev/null +++ b/rma_invoice/models/rma_order_line.py @@ -0,0 +1,76 @@ +# Copyright 2022 ForgeFlow S.L. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) +from odoo import api, fields, models +from odoo.tools.safe_eval import safe_eval + + +class RmaOrderLine(models.Model): + + _inherit = "rma.order.line" + + invoice_policy = fields.Selection( + string="Invoice policy", + selection=[ + ("no", "No Service Invoice"), + ("yes", "Create Service Invoice"), + ], + ) + + invoice_ids = fields.Many2many(comodel_name="account.move", string="Invoices") + + invoice_count = fields.Integer( + string="Invoices count", + compute="_compute_invoice_count", + ) + + @api.depends( + "invoice_ids", + ) + def _compute_invoice_count(self): + for rec in self: + rec.invoice_count = len(rec.invoice_ids) + + def action_show_invoices(self): + self.ensure_one() + action = {} + if self.type == "customer": + action = self.env["ir.actions.actions"]._for_xml_id( + "account.action_move_out_invoice_type" + ) + elif self.type == "supplier": + action = self.env["ir.actions.actions"]._for_xml_id( + "account.action_move_in_invoice_type" + ) + if len(self.invoice_ids) <= 1: + form_view = [(self.env.ref("account.view_move_form").id, "form")] + if "views" in action: + action["views"] = form_view + [ + (state, view) for state, view in action["views"] if view != "form" + ] + else: + action["views"] = form_view + action["res_id"] = self.invoice_ids.ids[0] + else: + domain = safe_eval(action["domain"]) or [] + domain += [("id", "in", self.invoice_ids.ids)] + action["domain"] = action["domain"] + return action + + def _prepare_rma_line_from_stock_move(self, sm, lot=False): + operation_model = self.env["rma.operation"] + res = super()._prepare_rma_line_from_stock_move() + if res.get("operation_id", False): + operation = operation_model.browse(res.get("operation_id", False)) + res.update( + { + "invoice_policy": operation.invoice_policy, + } + ) + return res + + @api.onchange("operation_id") + def _onchange_operation_id(self): + res = super()._onchange_operation_id() + if self.operation_id: + self.invoice_policy = self.operation_id.invoice_policy + return res diff --git a/rma_invoice/readme/CONTRIBUTORS.rst b/rma_invoice/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000..b647a292 --- /dev/null +++ b/rma_invoice/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Christopher Ormaza diff --git a/rma_invoice/readme/DESCRIPTION.rst b/rma_invoice/readme/DESCRIPTION.rst new file mode 100644 index 00000000..09633ef9 --- /dev/null +++ b/rma_invoice/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +This module add possibility to create invoice for extra services on RMA creation diff --git a/rma_invoice/security/ir.model.access.csv b/rma_invoice/security/ir.model.access.csv new file mode 100644 index 00000000..c56cf38a --- /dev/null +++ b/rma_invoice/security/ir.model.access.csv @@ -0,0 +1,2 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_wizard_create_invoice_rma,access_wizard_create_invoice_rma,model_wizard_create_invoice_rma,,1,1,1,1 diff --git a/rma_invoice/static/description/index.html b/rma_invoice/static/description/index.html new file mode 100644 index 00000000..3806203e --- /dev/null +++ b/rma_invoice/static/description/index.html @@ -0,0 +1,421 @@ + + + + + + +RMA Invoices Related + + + + + + diff --git a/rma_invoice/views/account_move_view.xml b/rma_invoice/views/account_move_view.xml new file mode 100644 index 00000000..ded8a94b --- /dev/null +++ b/rma_invoice/views/account_move_view.xml @@ -0,0 +1,31 @@ + + + + + + account.move.form + account.move + + + + + + + + + + + diff --git a/rma_invoice/views/rma_operation_view.xml b/rma_invoice/views/rma_operation_view.xml new file mode 100644 index 00000000..ec8401e8 --- /dev/null +++ b/rma_invoice/views/rma_operation_view.xml @@ -0,0 +1,17 @@ + + + + + + rma.operation.form.view + rma.operation + + + + + + + + + + diff --git a/rma_invoice/views/rma_order_line_view.xml b/rma_invoice/views/rma_order_line_view.xml new file mode 100644 index 00000000..5e066369 --- /dev/null +++ b/rma_invoice/views/rma_order_line_view.xml @@ -0,0 +1,43 @@ + + + + + + rma.order.line.form.view + rma.order.line + + + + + + + + + +