diff --git a/rma_sale/README.rst b/rma_sale/README.rst new file mode 100644 index 00000000..1e67d920 --- /dev/null +++ b/rma_sale/README.rst @@ -0,0 +1,117 @@ +============================================================= +Return Merchandise Authorization Management - Link with Sales +============================================================= + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! 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-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-OCA%2Frma-lightgray.png?logo=github + :target: https://github.com/OCA/rma/tree/12.0/rma_sale + :alt: OCA/rma +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/rma-12-0/rma-12-0-rma_sale + :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/12.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allows you to link a sales order to an RMA. +This can be done by creating an RMA from scratch and selecting the sales +order, creating one or more RMAs from a sales order form view or from a sales +order web portal page. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +To use this module, you need to: + +#. Go to *RMA > Orders* and create a new RMA. +#. Select a sales order to be linked to the RMA if you want. +#. Now you can do the rest of the instructions described in the + *readme* of the rma module. + +If you want to create one or more RMAs from a sale order: + +#. Go to *Sales > Orders > Orders*. +#. Create a new sales order or select an existing one. +#. If the sales order is in 'Sales Order' state you can see in the status bar + a button labeled 'Create RMA', click it and a wizard will appear. +#. Modify the data at your convenience and click on 'Accept' button. +#. As many RMAs as lines with quantity greater than zero will be created. + Those RMAs will be linked to the sales order. + +The customer can also create RMAs from a sales order portal page: + +#. Go to a confirmed sales order portal page. +#. In the left sidebar you can see a button named 'Request RMAs'. +#. By clicking on this button a popup will appear to allow you to define + the quantity per product and delivery order line. +#. Click on the 'Request RMAs' button and RMAs will be created linked to + the sales order. + +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 +~~~~~~~ + +* Tecnativa + +Contributors +~~~~~~~~~~~~ + +* `Tecnativa `_: + + * Ernesto Tejeda + * Pedro M. Baeza + * David Vidal + +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-ernestotejeda| image:: https://github.com/ernestotejeda.png?size=40px + :target: https://github.com/ernestotejeda + :alt: ernestotejeda + +Current `maintainer `__: + +|maintainer-ernestotejeda| + +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_sale/__init__.py b/rma_sale/__init__.py new file mode 100644 index 00000000..57055b3c --- /dev/null +++ b/rma_sale/__init__.py @@ -0,0 +1,5 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import controllers +from . import models +from . import wizard diff --git a/rma_sale/__manifest__.py b/rma_sale/__manifest__.py new file mode 100644 index 00000000..0c0efb2a --- /dev/null +++ b/rma_sale/__manifest__.py @@ -0,0 +1,25 @@ +# Copyright 2020 Tecnativa - Ernesto Tejeda +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +{ + "name": "Return Merchandise Authorization Management - Link with Sales", + "summary": "Sale Order - Return Merchandise Authorization (RMA)", + "version": "12.0.1.0.0", + "development_status": "Beta", + "category": "RMA", + "website": "https://github.com/OCA/rma", + "author": "Tecnativa, Odoo Community Association (OCA)", + "maintainers": ["ernestotejeda"], + "license": "AGPL-3", + "depends": [ + "rma", + "sale", + ], + "data": [ + "views/assets.xml", + "views/report_rma.xml", + "views/rma_views.xml", + "views/sale_views.xml", + "views/sale_portal_template.xml", + "wizard/sale_order_rma_wizard_views.xml", + ], +} diff --git a/rma_sale/controllers/__init__.py b/rma_sale/controllers/__init__.py new file mode 100644 index 00000000..c3c3eb4d --- /dev/null +++ b/rma_sale/controllers/__init__.py @@ -0,0 +1,4 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import rma_portal +from . import sale_portal diff --git a/rma_sale/controllers/rma_portal.py b/rma_sale/controllers/rma_portal.py new file mode 100644 index 00000000..505ab5c4 --- /dev/null +++ b/rma_sale/controllers/rma_portal.py @@ -0,0 +1,13 @@ +# Copyright 2020 Tecnativa - Ernesto Tejeda +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo.addons.rma.controllers.main import PortalRma + + +class PortalRma(PortalRma): + + def _get_filter_domain(self, kw): + res = super()._get_filter_domain(kw) + if 'sale_id' in kw: + res.append(('order_id', '=', int(kw['sale_id']))) + return res diff --git a/rma_sale/controllers/sale_portal.py b/rma_sale/controllers/sale_portal.py new file mode 100644 index 00000000..1ce25893 --- /dev/null +++ b/rma_sale/controllers/sale_portal.py @@ -0,0 +1,40 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import http, _ +from odoo.exceptions import AccessError, MissingError +from odoo.http import request +from odoo.addons.sale.controllers.portal import CustomerPortal + + +class CustomerPortal(CustomerPortal): + @http.route(['/my/orders//requestrma'], type='http', + auth="public", methods=['POST'], website=True) + def request_rma(self, order_id, access_token=None, **post): + try: + order_sudo = self._document_check_access('sale.order', order_id, + access_token=access_token) + except (AccessError, MissingError): + return request.redirect('/my') + order_obj = request.env['sale.order'] + wizard_obj = request.env['sale.order.rma.wizard'] + # Set wizard line vals + mapped_vals = {} + for name, value in post.items(): + row, field_name = name.split('-', 1) + mapped_vals.setdefault(row, {}).update({field_name: value}) + line_vals = [(0, 0, vals) for vals in mapped_vals.values()] + # Create wizard an generate rmas + location_id = order_obj.browse(order_id).warehouse_id.rma_loc_id.id + wizard = wizard_obj.with_context(active_id=order_id).create({ + 'line_ids': line_vals, + 'location_id': location_id + }) + rma = wizard.create_rma(from_portal=True) + for rec in rma: + rec.origin += _(' (Portal)') + if len(rma) == 0: + route = order_sudo.get_portal_url() + else: + route = "/my/rmas?sale_id=%d" % order_id + return request.redirect(route) diff --git a/rma_sale/i18n/es.po b/rma_sale/i18n/es.po new file mode 100644 index 00000000..0d3e1091 --- /dev/null +++ b/rma_sale/i18n/es.po @@ -0,0 +1,337 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * rma_sale +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2020-07-01 04:40+0000\n" +"PO-Revision-Date: 2020-07-01 00:41-0400\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: \n" +"X-Generator: Poedit 2.0.6\n" + +#. module: rma_sale +#: code:addons/rma_sale/controllers/sale_portal.py:35 +#, python-format +msgid " (Portal)" +msgstr "" + +#. module: rma_sale +#: code:addons/rma_sale/wizard/sale_order_rma_wizard.py:48 +#, python-format +msgid " has been created." +msgstr " ha sido creado." + +#. module: rma_sale +#: code:addons/rma_sale/wizard/sale_order_rma_wizard.py:50 +#, python-format +msgid " have been created." +msgstr " han sido creados." + +#. module: rma_sale +#: model_terms:ir.ui.view,arch_db:rma_sale.sale_order_portal_template +msgid "&times;" +msgstr "" + +#. module: rma_sale +#: model_terms:ir.ui.view,arch_db:rma_sale.sale_order_portal_template +msgid " Request RMAs" +msgstr " Solicitar RMAs" + +#. module: rma_sale +#: model_terms:ir.ui.view,arch_db:rma_sale.sale_order_portal_template +msgid " Request RMAs" +msgstr " Solicitar RMAs" + +#. module: rma_sale +#: model_terms:ir.ui.view,arch_db:rma_sale.sale_order_portal_template +msgid " Cancel" +msgstr " Cancelar" + +#. module: rma_sale +#: model_terms:ir.ui.view,arch_db:rma_sale.sale_order_portal_content +msgid "" +"" +msgstr "" + +#. module: rma_sale +#: model_terms:ir.ui.view,arch_db:rma_sale.sale_order_portal_template +msgid "" +"\n" +" If an RMA has already been created for a " +"product in this sales order, it will not\n" +" be possible to create another one from the " +"web portal.\n" +" " +msgstr "" +"\n" +" Si ya se ha creado un RMA para un producto " +"de esta orden de venta, no será\n" +" posible crear otro desde el portal web.\n" +" " + +#. module: rma_sale +#: model_terms:ir.ui.view,arch_db:rma_sale.sale_order_portal_content +msgid "RMA" +msgstr "" + +#. module: rma_sale +#: model_terms:ir.ui.view,arch_db:rma_sale.report_rma_document +msgid "Requested operation:" +msgstr "Operación solicitada:" + +#. module: rma_sale +#: model_terms:ir.ui.view,arch_db:rma_sale.portal_rma_page +msgid "Requested operation" +msgstr "Operación solicitada:" + +#. module: rma_sale +#: model_terms:ir.ui.view,arch_db:rma_sale.report_rma_document +msgid "Sale order:" +msgstr "Orden de venta:" + +#. module: rma_sale +#: model_terms:ir.ui.view,arch_db:rma_sale.portal_rma_page +msgid "Sale order" +msgstr "Orden de venta" + +#. module: rma_sale +#: model_terms:ir.ui.view,arch_db:rma_sale.=sale_order_rma_wizard_form_view +msgid "Accept" +msgstr "Aceptar" + +#. module: rma_sale +#: model_terms:ir.ui.view,arch_db:rma_sale.=sale_order_rma_wizard_form_view +msgid "Cancel" +msgstr "Cancelar" + +#. module: rma_sale +#: model:ir.model.fields,field_description:rma_sale.field_sale_order_line_rma_wizard__uom_category_id +msgid "Category" +msgstr "Categoría" + +#. module: rma_sale +#: model_terms:ir.ui.view,arch_db:rma_sale.sale_order_portal_template +msgid "Close" +msgstr "Cerrar" + +#. module: rma_sale +#: model:ir.model.fields,help:rma_sale.field_sale_order_line_rma_wizard__uom_category_id +msgid "" +"Conversion between Units of Measure can only occur if they belong to the " +"same category. The conversion will be made based on the ratios." +msgstr "" +"La conversión entre las unidades de medidas sólo pueden ocurrir si " +"pertenecen a la misma categoría. La conversión se basará en los ratios " +"establecidos." + +#. module: rma_sale +#: code:addons/rma_sale/models/sale.py:48 +#: model_terms:ir.ui.view,arch_db:rma_sale.view_order_form +#, python-format +msgid "Create RMA" +msgstr "Crear RMA" + +#. module: rma_sale +#: model:ir.actions.act_window,name:rma_sale.sale_order_create_rma_action +msgid "Create RMAs" +msgstr "Crear RMA" + +#. module: rma_sale +#: model:ir.model.fields,field_description:rma_sale.field_sale_order_line_rma_wizard__create_uid +#: model:ir.model.fields,field_description:rma_sale.field_sale_order_rma_wizard__create_uid +msgid "Created by" +msgstr "Creado por" + +#. module: rma_sale +#: model:ir.model.fields,field_description:rma_sale.field_sale_order_line_rma_wizard__create_date +#: model:ir.model.fields,field_description:rma_sale.field_sale_order_rma_wizard__create_date +msgid "Created on" +msgstr "Creado el" + +#. module: rma_sale +#: model_terms:ir.ui.view,arch_db:rma_sale.sale_order_portal_template +msgid "Delivery" +msgstr "Entrega" + +#. module: rma_sale +#: model:ir.model.fields,field_description:rma_sale.field_sale_order_line_rma_wizard__picking_id +msgid "Delivery order" +msgstr "Orden de entrega" + +#. module: rma_sale +#: model:ir.model.fields,field_description:rma_sale.field_sale_order_line_rma_wizard__display_name +#: model:ir.model.fields,field_description:rma_sale.field_sale_order_rma_wizard__display_name +msgid "Display Name" +msgstr "Nombre mostrado" + +#. module: rma_sale +#: model:ir.model.fields,field_description:rma_sale.field_rma__domain_move_ids +msgid "Domain Move" +msgstr "Dominio de movimientos" + +#. module: rma_sale +#: model:ir.model.fields,field_description:rma_sale.field_rma__domain_picking_ids +msgid "Domain Picking" +msgstr "Dominio de entregas" + +#. module: rma_sale +#: model:ir.model.fields,field_description:rma_sale.field_rma__domain_product_ids +msgid "Domain Product" +msgstr "Dominio de productos" + +#. module: rma_sale +#: model:ir.model.fields,field_description:rma_sale.field_sale_order_line_rma_wizard__id +#: model:ir.model.fields,field_description:rma_sale.field_sale_order_rma_wizard__id +msgid "ID" +msgstr "" + +#. module: rma_sale +#: model:ir.model.fields,field_description:rma_sale.field_stock_move__is_sale_delivery +#, fuzzy +#| msgid "Delivery" +msgid "Is Sale Delivery" +msgstr "Es entrega de orden de venta" + +#. module: rma_sale +#: model:ir.model.fields,field_description:rma_sale.field_sale_order_line_rma_wizard____last_update +#: model:ir.model.fields,field_description:rma_sale.field_sale_order_rma_wizard____last_update +msgid "Last Modified on" +msgstr "Última modificación en" + +#. module: rma_sale +#: model:ir.model.fields,field_description:rma_sale.field_sale_order_line_rma_wizard__write_uid +#: model:ir.model.fields,field_description:rma_sale.field_sale_order_rma_wizard__write_uid +msgid "Last Updated by" +msgstr "Última actualización por" + +#. module: rma_sale +#: model:ir.model.fields,field_description:rma_sale.field_sale_order_line_rma_wizard__write_date +#: model:ir.model.fields,field_description:rma_sale.field_sale_order_rma_wizard__write_date +msgid "Last Updated on" +msgstr "Última actualización el" + +#. module: rma_sale +#: model:ir.model.fields,field_description:rma_sale.field_sale_order_rma_wizard__line_ids +msgid "Lines" +msgstr "Líneas" + +#. module: rma_sale +#: model:ir.model.fields,field_description:rma_sale.field_sale_order_line_rma_wizard__move_id +msgid "Move" +msgstr "Movimiento" + +#. module: rma_sale +#: model:ir.model.fields,field_description:rma_sale.field_sale_order_line_rma_wizard__order_id +#: model:ir.model.fields,field_description:rma_sale.field_sale_order_rma_wizard__order_id +msgid "Order" +msgstr "Orden" + +#. module: rma_sale +#: model:ir.model.fields,field_description:rma_sale.field_rma__picking_id +msgid "Origin Delivery" +msgstr "Orden de Entrega" + +#. module: rma_sale +#: model:ir.model.fields,field_description:rma_sale.field_rma__move_id +msgid "Origin move" +msgstr "Movimiento" + +#. module: rma_sale +#: model:ir.model.fields,field_description:rma_sale.field_sale_order_line_rma_wizard__picking_ids +msgid "Picking" +msgstr "Dominio de órdenes de entrega" + +#. module: rma_sale +#: model:ir.model.fields,field_description:rma_sale.field_rma__product_id +#: model:ir.model.fields,field_description:rma_sale.field_sale_order_line_rma_wizard__product_id +#: model_terms:ir.ui.view,arch_db:rma_sale.sale_order_portal_template +msgid "Product" +msgstr "Producto" + +#. module: rma_sale +#: model:ir.model.fields,field_description:rma_sale.field_sale_order_line_rma_wizard__quantity +#: model_terms:ir.ui.view,arch_db:rma_sale.sale_order_portal_template +msgid "Quantity" +msgstr "Cantidad" + +#. module: rma_sale +#: model:ir.model,name:rma_sale.model_rma +#: model_terms:ir.ui.view,arch_db:rma_sale.view_order_form +msgid "RMA" +msgstr "" + +#. module: rma_sale +#: model:ir.model.fields,field_description:rma_sale.field_sale_order__rma_count +msgid "RMA count" +msgstr "Cantidad de RMAs" + +#. module: rma_sale +#: model:ir.model.fields,field_description:rma_sale.field_sale_order_rma_wizard__location_id +msgid "RMA location" +msgstr "Ubicación de RMA" + +#. module: rma_sale +#: model:ir.model.fields,field_description:rma_sale.field_sale_order__rma_ids +msgid "RMAs" +msgstr "" + +#. module: rma_sale +#: model_terms:ir.ui.view,arch_db:rma_sale.sale_order_portal_template +msgid "Request RMAs" +msgstr "Solicitar RMAs" + +#. module: rma_sale +#: model:ir.model.fields,field_description:rma_sale.field_sale_order_line_rma_wizard__operation_id +#: model_terms:ir.ui.view,arch_db:rma_sale.sale_order_portal_template +msgid "Requested operation" +msgstr "Operación solicitada" + +#. module: rma_sale +#: model:ir.model,name:rma_sale.model_sale_order +#: model:ir.model.fields,field_description:rma_sale.field_rma__order_id +msgid "Sale Order" +msgstr "Pedido de venta" + +#. module: rma_sale +#: model:ir.model,name:rma_sale.model_sale_order_line_rma_wizard +msgid "Sale Order Line Rma Wizard" +msgstr "Linea de Asistente de Orden de Venta - RMA " + +#. module: rma_sale +#: model:ir.model,name:rma_sale.model_sale_order_rma_wizard +msgid "Sale Order Rma Wizard" +msgstr "Asistente de Orden de Venta - RMA" + +#. module: rma_sale +#: model:ir.model,name:rma_sale.model_sale_order_line +msgid "Sales Order Line" +msgstr "Línea de pedido de venta" + +#. module: rma_sale +#: model:ir.model,name:rma_sale.model_stock_move +msgid "Stock Move" +msgstr "Movimiento" + +#. module: rma_sale +#: model:ir.model.fields,field_description:rma_sale.field_sale_order_line_rma_wizard__uom_id +msgid "Unit of Measure" +msgstr "Unidad de medida" + +#. module: rma_sale +#: model:ir.model.fields,field_description:rma_sale.field_sale_order_line_rma_wizard__wizard_id +msgid "Wizard" +msgstr "Asistente" + +#. module: rma_sale +#: code:addons/rma_sale/models/sale.py:34 +#, python-format +msgid "You may only create RMAs from a confirmed or done sale order." +msgstr "Solo puedes crear RMAs desde una orden de venta confirmada o hecha." diff --git a/rma_sale/i18n/rma_sale.pot b/rma_sale/i18n/rma_sale.pot new file mode 100644 index 00000000..3de688c5 --- /dev/null +++ b/rma_sale/i18n/rma_sale.pot @@ -0,0 +1,305 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * rma_sale +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: rma_sale +#: code:addons/rma_sale/controllers/sale_portal.py:35 +#, python-format +msgid " (Portal)" +msgstr "" + +#. module: rma_sale +#: code:addons/rma_sale/wizard/sale_order_rma_wizard.py:48 +#, python-format +msgid " has been created." +msgstr "" + +#. module: rma_sale +#: code:addons/rma_sale/wizard/sale_order_rma_wizard.py:50 +#, python-format +msgid " have been created." +msgstr "" + +#. module: rma_sale +#: model_terms:ir.ui.view,arch_db:rma_sale.sale_order_portal_template +msgid "&times;" +msgstr "" + +#. module: rma_sale +#: model_terms:ir.ui.view,arch_db:rma_sale.sale_order_portal_template +msgid " Request RMAs" +msgstr "" + +#. module: rma_sale +#: model_terms:ir.ui.view,arch_db:rma_sale.sale_order_portal_template +msgid " Request RMAs" +msgstr "" + +#. module: rma_sale +#: model_terms:ir.ui.view,arch_db:rma_sale.sale_order_portal_template +msgid " Cancel" +msgstr "" + +#. module: rma_sale +#: model_terms:ir.ui.view,arch_db:rma_sale.sale_order_portal_content +msgid "" +msgstr "" + +#. module: rma_sale +#: model_terms:ir.ui.view,arch_db:rma_sale.sale_order_portal_template +msgid "\n" +" If an RMA has already been created for a product in this sales order, it will not\n" +" be possible to create another one from the web portal.\n" +" " +msgstr "" + +#. module: rma_sale +#: model_terms:ir.ui.view,arch_db:rma_sale.sale_order_portal_content +msgid "RMA" +msgstr "" + +#. module: rma_sale +#: model_terms:ir.ui.view,arch_db:rma_sale.report_rma_document +msgid "Requested operation:" +msgstr "" + +#. module: rma_sale +#: model_terms:ir.ui.view,arch_db:rma_sale.portal_rma_page +msgid "Requested operation" +msgstr "" + +#. module: rma_sale +#: model_terms:ir.ui.view,arch_db:rma_sale.report_rma_document +msgid "Sale order:" +msgstr "" + +#. module: rma_sale +#: model_terms:ir.ui.view,arch_db:rma_sale.portal_rma_page +msgid "Sale order" +msgstr "" + +#. module: rma_sale +#: model_terms:ir.ui.view,arch_db:rma_sale.=sale_order_rma_wizard_form_view +msgid "Accept" +msgstr "" + +#. module: rma_sale +#: model:ir.model.fields,field_description:rma_sale.field_rma__allowed_move_ids +msgid "Allowed Move" +msgstr "" + +#. module: rma_sale +#: model:ir.model.fields,field_description:rma_sale.field_rma__allowed_picking_ids +#: model:ir.model.fields,field_description:rma_sale.field_sale_order_line_rma_wizard__allowed_picking_ids +msgid "Allowed Picking" +msgstr "" + +#. module: rma_sale +#: model:ir.model.fields,field_description:rma_sale.field_rma__allowed_product_ids +#: model:ir.model.fields,field_description:rma_sale.field_sale_order_line_rma_wizard__allowed_product_ids +msgid "Allowed Product" +msgstr "" + +#. module: rma_sale +#: model_terms:ir.ui.view,arch_db:rma_sale.=sale_order_rma_wizard_form_view +msgid "Cancel" +msgstr "" + +#. module: rma_sale +#: model:ir.model.fields,field_description:rma_sale.field_sale_order_line_rma_wizard__uom_category_id +msgid "Category" +msgstr "" + +#. module: rma_sale +#: model_terms:ir.ui.view,arch_db:rma_sale.sale_order_portal_template +msgid "Close" +msgstr "" + +#. module: rma_sale +#: model:ir.model.fields,help:rma_sale.field_sale_order_line_rma_wizard__uom_category_id +msgid "Conversion between Units of Measure can only occur if they belong to the same category. The conversion will be made based on the ratios." +msgstr "" + +#. module: rma_sale +#: code:addons/rma_sale/models/sale.py:48 +#: model_terms:ir.ui.view,arch_db:rma_sale.view_order_form +#, python-format +msgid "Create RMA" +msgstr "" + +#. module: rma_sale +#: model:ir.actions.act_window,name:rma_sale.sale_order_create_rma_action +msgid "Create RMAs" +msgstr "" + +#. module: rma_sale +#: model:ir.model.fields,field_description:rma_sale.field_sale_order_line_rma_wizard__create_uid +#: model:ir.model.fields,field_description:rma_sale.field_sale_order_rma_wizard__create_uid +msgid "Created by" +msgstr "" + +#. module: rma_sale +#: model:ir.model.fields,field_description:rma_sale.field_sale_order_line_rma_wizard__create_date +#: model:ir.model.fields,field_description:rma_sale.field_sale_order_rma_wizard__create_date +msgid "Created on" +msgstr "" + +#. module: rma_sale +#: model_terms:ir.ui.view,arch_db:rma_sale.sale_order_portal_template +msgid "Delivery" +msgstr "" + +#. module: rma_sale +#: model:ir.model.fields,field_description:rma_sale.field_sale_order_line_rma_wizard__picking_id +msgid "Delivery order" +msgstr "" + +#. module: rma_sale +#: model:ir.model.fields,field_description:rma_sale.field_sale_order_line_rma_wizard__display_name +#: model:ir.model.fields,field_description:rma_sale.field_sale_order_rma_wizard__display_name +msgid "Display Name" +msgstr "" + +#. module: rma_sale +#: model:ir.model.fields,field_description:rma_sale.field_sale_order_line_rma_wizard__id +#: model:ir.model.fields,field_description:rma_sale.field_sale_order_rma_wizard__id +msgid "ID" +msgstr "" + +#. module: rma_sale +#: model:ir.model.fields,field_description:rma_sale.field_sale_order_line_rma_wizard____last_update +#: model:ir.model.fields,field_description:rma_sale.field_sale_order_rma_wizard____last_update +msgid "Last Modified on" +msgstr "" + +#. module: rma_sale +#: model:ir.model.fields,field_description:rma_sale.field_sale_order_line_rma_wizard__write_uid +#: model:ir.model.fields,field_description:rma_sale.field_sale_order_rma_wizard__write_uid +msgid "Last Updated by" +msgstr "" + +#. module: rma_sale +#: model:ir.model.fields,field_description:rma_sale.field_sale_order_line_rma_wizard__write_date +#: model:ir.model.fields,field_description:rma_sale.field_sale_order_rma_wizard__write_date +msgid "Last Updated on" +msgstr "" + +#. module: rma_sale +#: model:ir.model.fields,field_description:rma_sale.field_sale_order_rma_wizard__line_ids +msgid "Lines" +msgstr "" + +#. module: rma_sale +#: model:ir.model.fields,field_description:rma_sale.field_sale_order_line_rma_wizard__move_id +msgid "Move" +msgstr "" + +#. module: rma_sale +#: model:ir.model.fields,field_description:rma_sale.field_sale_order_line_rma_wizard__order_id +#: model:ir.model.fields,field_description:rma_sale.field_sale_order_rma_wizard__order_id +msgid "Order" +msgstr "" + +#. module: rma_sale +#: model:ir.model.fields,field_description:rma_sale.field_rma__picking_id +msgid "Origin Delivery" +msgstr "" + +#. module: rma_sale +#: model:ir.model.fields,field_description:rma_sale.field_rma__move_id +msgid "Origin move" +msgstr "" + +#. module: rma_sale +#: model:ir.model.fields,field_description:rma_sale.field_rma__product_id +#: model:ir.model.fields,field_description:rma_sale.field_sale_order_line_rma_wizard__product_id +#: model_terms:ir.ui.view,arch_db:rma_sale.sale_order_portal_template +msgid "Product" +msgstr "" + +#. module: rma_sale +#: model:ir.model.fields,field_description:rma_sale.field_sale_order_line_rma_wizard__quantity +#: model_terms:ir.ui.view,arch_db:rma_sale.sale_order_portal_template +msgid "Quantity" +msgstr "" + +#. module: rma_sale +#: model:ir.model,name:rma_sale.model_rma +#: model_terms:ir.ui.view,arch_db:rma_sale.view_order_form +msgid "RMA" +msgstr "" + +#. module: rma_sale +#: model:ir.model.fields,field_description:rma_sale.field_sale_order__rma_count +msgid "RMA count" +msgstr "" + +#. module: rma_sale +#: model:ir.model.fields,field_description:rma_sale.field_sale_order_rma_wizard__location_id +msgid "RMA location" +msgstr "" + +#. module: rma_sale +#: model:ir.model.fields,field_description:rma_sale.field_sale_order__rma_ids +msgid "RMAs" +msgstr "" + +#. module: rma_sale +#: model_terms:ir.ui.view,arch_db:rma_sale.sale_order_portal_template +msgid "Request RMAs" +msgstr "" + +#. module: rma_sale +#: model:ir.model.fields,field_description:rma_sale.field_sale_order_line_rma_wizard__operation_id +#: model_terms:ir.ui.view,arch_db:rma_sale.sale_order_portal_template +msgid "Requested operation" +msgstr "" + +#. module: rma_sale +#: model:ir.model,name:rma_sale.model_sale_order +#: model:ir.model.fields,field_description:rma_sale.field_rma__order_id +msgid "Sale Order" +msgstr "" + +#. module: rma_sale +#: model:ir.model,name:rma_sale.model_sale_order_line_rma_wizard +msgid "Sale Order Line Rma Wizard" +msgstr "" + +#. module: rma_sale +#: model:ir.model,name:rma_sale.model_sale_order_rma_wizard +msgid "Sale Order Rma Wizard" +msgstr "" + +#. module: rma_sale +#: model:ir.model,name:rma_sale.model_sale_order_line +msgid "Sales Order Line" +msgstr "" + +#. module: rma_sale +#: model:ir.model.fields,field_description:rma_sale.field_sale_order_line_rma_wizard__uom_id +msgid "Unit of Measure" +msgstr "" + +#. module: rma_sale +#: model:ir.model.fields,field_description:rma_sale.field_sale_order_line_rma_wizard__wizard_id +msgid "Wizard" +msgstr "" + +#. module: rma_sale +#: code:addons/rma_sale/models/sale.py:34 +#, python-format +msgid "You may only create RMAs from a confirmed or done sale order." +msgstr "" + diff --git a/rma_sale/models/__init__.py b/rma_sale/models/__init__.py new file mode 100644 index 00000000..d8e54bcb --- /dev/null +++ b/rma_sale/models/__init__.py @@ -0,0 +1,4 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import rma +from . import sale diff --git a/rma_sale/models/rma.py b/rma_sale/models/rma.py new file mode 100644 index 00000000..c647e771 --- /dev/null +++ b/rma_sale/models/rma.py @@ -0,0 +1,83 @@ +# Copyright 2020 Tecnativa - Ernesto Tejeda +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + + +class Rma(models.Model): + _inherit = "rma" + + order_id = fields.Many2one( + comodel_name='sale.order', + string='Sale Order', + domain="[" + " ('partner_id', 'child_of', commercial_partner_id)," + " ('state', 'in', ['sale', 'done'])," + "]", + readonly=True, + states={'draft': [('readonly', False)]}, + ) + allowed_picking_ids = fields.Many2many( + comodel_name='stock.picking', + compute="_compute_allowed_picking_ids", + ) + picking_id = fields.Many2one( + domain="[('id', 'in', allowed_picking_ids)]", + ) + allowed_move_ids = fields.Many2many( + comodel_name='sale.order.line', + compute="_compute_allowed_move_ids", + ) + move_id = fields.Many2one( + domain="[('id', 'in', allowed_move_ids)]", + ) + allowed_product_ids = fields.Many2many( + comodel_name='product.product', + compute="_compute_allowed_product_ids", + ) + product_id = fields.Many2one( + domain="[('id', 'in', allowed_product_ids)]", + ) + + @api.depends('partner_id', 'order_id') + def _compute_allowed_picking_ids(self): + domain = [('state', '=', 'done'), + ('picking_type_id.code', '=', 'outgoing')] + for rec in self: + # if rec.partner_id: + commercial_partner = rec.partner_id.commercial_partner_id + domain.append(('partner_id', 'child_of', commercial_partner.id)) + if rec.order_id: + domain.append(('sale_id', '=', rec.order_id.id)) + rec.allowed_picking_ids = self.env['stock.picking'].search(domain) + + @api.depends('order_id', 'picking_id') + def _compute_allowed_move_ids(self): + for rec in self: + if rec.order_id: + order_move = rec.order_id.order_line.mapped('move_ids') + rec.allowed_move_ids = order_move.filtered( + lambda r: r.picking_id == self.picking_id).ids + else: + rec.allowed_move_ids = self.picking_id.move_lines.ids + + @api.depends('order_id') + def _compute_allowed_product_ids(self): + for rec in self: + if rec.order_id: + order_product = rec.order_id.order_line.mapped('product_id') + rec.allowed_product_ids = order_product.filtered( + lambda r: r.type in ['consu', 'product']).ids + else: + rec.allowed_product_ids = self.env['product.product'].search( + [('type', 'in', ['consu', 'product'])]).ids + + @api.onchange("partner_id") + def _onchange_partner_id(self): + res = super()._onchange_partner_id() + self.order_id = False + return res + + @api.onchange('order_id') + def _onchange_order_id(self): + self.product_id = self.picking_id = False diff --git a/rma_sale/models/sale.py b/rma_sale/models/sale.py new file mode 100644 index 00000000..25cd223a --- /dev/null +++ b/rma_sale/models/sale.py @@ -0,0 +1,129 @@ +# Copyright 2020 Tecnativa - Ernesto Tejeda +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import _, fields, models +from odoo.exceptions import ValidationError + + +class SaleOrder(models.Model): + _inherit = "sale.order" + + # RMAs that were created from a sale order + rma_ids = fields.One2many( + comodel_name='rma', + inverse_name='order_id', + string='RMAs', + copy=False, + ) + rma_count = fields.Integer( + string='RMA count', + compute='_compute_rma_count', + ) + + def _compute_rma_count(self): + rma_data = self.env['rma'].read_group( + [('order_id', 'in', self.ids)], ['order_id'], ['order_id']) + mapped_data = dict( + [(r['order_id'][0], r['order_id_count']) for r in rma_data]) + for record in self: + record.rma_count = mapped_data.get(record.id, 0) + + def action_create_rma(self): + self.ensure_one() + if self.state not in ['sale', 'done']: + raise ValidationError(_("You may only create RMAs from a " + "confirmed or done sale order.")) + wizard_obj = self.env['sale.order.rma.wizard'] + line_vals = [(0, 0, { + 'product_id': data['product'].id, + 'quantity': data['quantity'], + 'uom_id': data['uom'].id, + 'picking_id': data['picking'] and data['picking'].id, + }) for data in self.get_delivery_rma_data()] + wizard = wizard_obj.with_context(active_id=self.id).create({ + 'line_ids': line_vals, + 'location_id': self.warehouse_id.rma_loc_id.id + }) + return { + 'name': _('Create RMA'), + 'type': 'ir.actions.act_window', + 'view_type': 'form', + 'view_mode': 'form', + 'res_model': 'sale.order.rma.wizard', + 'res_id': wizard.id, + 'target': 'new', + } + + def action_view_rma(self): + self.ensure_one() + action = self.env.ref('rma.rma_action').read()[0] + rma = self.rma_ids + if len(rma) == 1: + action.update( + res_id=rma.id, + view_mode="form", + ) + else: + action['domain'] = [('id', 'in', rma.ids)] + return action + + def get_delivery_rma_data(self): + self.ensure_one() + data = [] + for line in self.order_line: + data += line.prepare_sale_rma_data() + return data + + def get_portal_delivery_rma_data(self): + self.ensure_one() + data = [] + + rma_product = self.rma_ids.mapped('product_id') + for line in self.order_line.filtered( + lambda r: r.product_id not in rma_product): + data += line.prepare_sale_rma_data() + return data + + +class SaleOrderLine(models.Model): + _inherit = "sale.order.line" + + def get_delivery_move(self): + self.ensure_one() + return self.move_ids.filtered(lambda r: ( + self.product_id == r.product_id + and r.state == 'done' + and not r.scrapped + and r.location_dest_id.usage == "customer" + and (not r.origin_returned_move_id + or (r.origin_returned_move_id and r.to_refund)) + )) + + def prepare_sale_rma_data(self): + self.ensure_one() + product = self.product_id + if self.product_id.type != 'product': + return {} + moves = self.get_delivery_move() + data = [] + if moves: + for move in moves: + qty = move.product_uom_qty + move_dest = move.move_dest_ids.filtered( + lambda r: r.state in ['partially_available', + 'assigned', 'done']) + qty -= sum(move_dest.mapped('product_uom_qty')) + data.append({ + 'product': product, + 'quantity': qty, + 'uom': move.product_uom, + 'picking': move.picking_id, + }) + else: + data.append({ + 'product': product, + 'quantity': self.qty_delivered, + 'uom': self.product_uom, + 'picking': False, + }) + return data diff --git a/rma_sale/readme/CONTRIBUTORS.rst b/rma_sale/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000..d4052271 --- /dev/null +++ b/rma_sale/readme/CONTRIBUTORS.rst @@ -0,0 +1,5 @@ +* `Tecnativa `_: + + * Ernesto Tejeda + * Pedro M. Baeza + * David Vidal diff --git a/rma_sale/readme/DESCRIPTION.rst b/rma_sale/readme/DESCRIPTION.rst new file mode 100644 index 00000000..baff386c --- /dev/null +++ b/rma_sale/readme/DESCRIPTION.rst @@ -0,0 +1,4 @@ +This module allows you to link a sales order to an RMA. +This can be done by creating an RMA from scratch and selecting the sales +order, creating one or more RMAs from a sales order form view or from a sales +order web portal page. diff --git a/rma_sale/readme/USAGE.rst b/rma_sale/readme/USAGE.rst new file mode 100644 index 00000000..fd3026cc --- /dev/null +++ b/rma_sale/readme/USAGE.rst @@ -0,0 +1,25 @@ +To use this module, you need to: + +#. Go to *RMA > Orders* and create a new RMA. +#. Select a sales order to be linked to the RMA if you want. +#. Now you can do the rest of the instructions described in the + *readme* of the rma module. + +If you want to create one or more RMAs from a sale order: + +#. Go to *Sales > Orders > Orders*. +#. Create a new sales order or select an existing one. +#. If the sales order is in 'Sales Order' state you can see in the status bar + a button labeled 'Create RMA', click it and a wizard will appear. +#. Modify the data at your convenience and click on 'Accept' button. +#. As many RMAs as lines with quantity greater than zero will be created. + Those RMAs will be linked to the sales order. + +The customer can also create RMAs from a sales order portal page: + +#. Go to a confirmed sales order portal page. +#. In the left sidebar you can see a button named 'Request RMAs'. +#. By clicking on this button a popup will appear to allow you to define + the quantity per product and delivery order line. +#. Click on the 'Request RMAs' button and RMAs will be created linked to + the sales order. diff --git a/rma_sale/static/description/icon.png b/rma_sale/static/description/icon.png new file mode 100644 index 00000000..3a0328b5 Binary files /dev/null and b/rma_sale/static/description/icon.png differ diff --git a/rma_sale/static/description/index.html b/rma_sale/static/description/index.html new file mode 100644 index 00000000..aaaca20d --- /dev/null +++ b/rma_sale/static/description/index.html @@ -0,0 +1,459 @@ + + + + + + +Return Merchandise Authorization Management - Link with Sales + + + + + + diff --git a/rma_sale/static/src/scss/rma_sale.scss b/rma_sale/static/src/scss/rma_sale.scss new file mode 100644 index 00000000..1b5a1b35 --- /dev/null +++ b/rma_sale/static/src/scss/rma_sale.scss @@ -0,0 +1,5 @@ +.request-rma-tbody { + td { + vertical-align: middle; + } +} diff --git a/rma_sale/tests/__init__.py b/rma_sale/tests/__init__.py new file mode 100644 index 00000000..89e73462 --- /dev/null +++ b/rma_sale/tests/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import test_rma_sale diff --git a/rma_sale/tests/test_rma_sale.py b/rma_sale/tests/test_rma_sale.py new file mode 100644 index 00000000..8150a4ff --- /dev/null +++ b/rma_sale/tests/test_rma_sale.py @@ -0,0 +1,68 @@ +# Copyright 2020 Tecnativa - Ernesto Tejeda +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo.tests import Form, SavepointCase + + +class TestRmaSale(SavepointCase): + @classmethod + def setUpClass(cls): + super(TestRmaSale, cls).setUpClass() + cls.res_partner = cls.env['res.partner'] + cls.product_product = cls.env['product.product'] + cls.sale_order = cls.env['sale.order'] + + cls.product_1 = cls.product_product.create({ + 'name': 'Product test 1', + 'type': 'product', + }) + cls.product_2 = cls.product_product.create({ + 'name': 'Product test 2', + 'type': 'product', + }) + cls.partner = cls.res_partner.create({ + 'name': 'Partner test', + }) + order_form = Form(cls.sale_order) + order_form.partner_id = cls.partner + with order_form.order_line.new() as line_form: + line_form.product_id = cls.product_1 + line_form.product_uom_qty = 5 + cls.sale_order = order_form.save() + cls.sale_order.action_confirm() + cls.order_out_picking = cls.sale_order.picking_ids + cls.order_out_picking.move_lines.quantity_done = 5 + cls.order_out_picking.button_validate() + + def test_create_rma_with_so(self): + rma_form = Form(self.env['rma']) + rma_form.partner_id = self.partner + rma_form.order_id = self.sale_order + rma_form.product_id = self.product_1 + rma_form.product_uom_qty = 5 + rma = rma_form.save() + rma.action_confirm() + self.assertTrue(rma.reception_move_id) + self.assertFalse(rma.reception_move_id.origin_returned_move_id) + + def test_create_rma_from_so(self): + order = self.sale_order + wizard_id = order.action_create_rma()['res_id'] + wizard = self.env['sale.order.rma.wizard'].browse(wizard_id) + rma = self.env['rma'].browse(wizard.create_and_open_rma()['res_id']) + self.assertEqual(rma.partner_id, order.partner_id) + self.assertEqual(rma.order_id, order) + self.assertEqual(rma.picking_id, self.order_out_picking) + self.assertEqual(rma.move_id, self.order_out_picking.move_lines) + self.assertEqual(rma.product_id, self.product_1) + self.assertEqual(rma.product_uom_qty, order.order_line.product_uom_qty) + self.assertEqual(rma.product_uom, order.order_line.product_uom) + self.assertEqual(rma.state, 'confirmed') + self.assertEqual( + rma.reception_move_id.origin_returned_move_id, + self.order_out_picking.move_lines, + ) + self.assertEqual( + rma.reception_move_id.picking_id + self.order_out_picking, + order.picking_ids, + ) diff --git a/rma_sale/views/assets.xml b/rma_sale/views/assets.xml new file mode 100644 index 00000000..e0a8aee1 --- /dev/null +++ b/rma_sale/views/assets.xml @@ -0,0 +1,8 @@ + + + + diff --git a/rma_sale/views/report_rma.xml b/rma_sale/views/report_rma.xml new file mode 100644 index 00000000..df29c25c --- /dev/null +++ b/rma_sale/views/report_rma.xml @@ -0,0 +1,17 @@ + + + + diff --git a/rma_sale/views/rma_views.xml b/rma_sale/views/rma_views.xml new file mode 100644 index 00000000..f00ce87f --- /dev/null +++ b/rma_sale/views/rma_views.xml @@ -0,0 +1,20 @@ + + + + + rma.view.form + rma + + + + + + + + + + + + + diff --git a/rma_sale/views/sale_portal_template.xml b/rma_sale/views/sale_portal_template.xml new file mode 100644 index 00000000..fad64c85 --- /dev/null +++ b/rma_sale/views/sale_portal_template.xml @@ -0,0 +1,126 @@ + + + + + diff --git a/rma_sale/views/sale_views.xml b/rma_sale/views/sale_views.xml new file mode 100644 index 00000000..7ef9a4b5 --- /dev/null +++ b/rma_sale/views/sale_views.xml @@ -0,0 +1,27 @@ + + + + sale.order.form.inherit + sale.order + + + +
+ +
+
+
+
diff --git a/rma_sale/wizard/__init__.py b/rma_sale/wizard/__init__.py new file mode 100644 index 00000000..f2e50b2e --- /dev/null +++ b/rma_sale/wizard/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import sale_order_rma_wizard diff --git a/rma_sale/wizard/sale_order_rma_wizard.py b/rma_sale/wizard/sale_order_rma_wizard.py new file mode 100644 index 00000000..370fee13 --- /dev/null +++ b/rma_sale/wizard/sale_order_rma_wizard.py @@ -0,0 +1,172 @@ +# Copyright 2020 Tecnativa - Ernesto Tejeda +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import _, api, fields, models +from odoo.addons import decimal_precision as dp + + +class SaleOrderRmaWizard(models.TransientModel): + _name = "sale.order.rma.wizard" + _description = 'Sale Order Rma Wizard' + + def _domain_location_id(self): + rma_loc = self.env['stock.warehouse'].search([]).mapped('rma_loc_id') + return [('id', 'child_of', rma_loc.ids)] + + order_id = fields.Many2one( + comodel_name='sale.order', + default=lambda self: self.env.context.get('active_id', False), + ) + line_ids = fields.One2many( + comodel_name='sale.order.line.rma.wizard', + inverse_name='wizard_id', + string='Lines', + ) + location_id = fields.Many2one( + comodel_name='stock.location', + string='RMA location', + domain=_domain_location_id, + default=lambda r: r.order_id.warehouse_id.rma_loc_id.id, + ) + + def create_rma_from_portal(self): + self.ensure_one() + + def create_rma(self, from_portal=None): + self.ensure_one() + lines = self.line_ids.filtered(lambda r: r.quantity > 0.0) + if from_portal: + rma_product = self.order_id.rma_ids.mapped('product_id') + lines = lines.filtered(lambda r: r.product_id not in rma_product) + val_list = [line._prepare_rma_values() for line in lines] + rma = self.env['rma'].create(val_list) + # post messages + msg_list = ['%s' + % (r.id, r.name) for r in rma] + msg = ', '.join(msg_list) + if len(msg_list) == 1: + self.order_id.message_post(body=_(msg + ' has been created.')) + elif len(msg_list) > 1: + self.order_id.message_post(body=_(msg + ' have been created.')) + rma.message_post_with_view( + 'mail.message_origin_link', + values={'self': rma, 'origin': self.order_id}, + subtype_id=self.env.ref('mail.mt_note').id, + ) + return rma + + def create_and_open_rma(self): + self.ensure_one() + rma = self.create_rma() + for rec in rma: + rec.action_confirm() + action = self.env.ref('rma.rma_action').read()[0] + if len(rma) > 1: + action['domain'] = [('id', 'in', rma.ids)] + elif rma: + action.update( + res_id=rma.id, + view_mode="form", + view_id=False, + views=False, + ) + return action + + +class SaleOrderLineRmaWizard(models.TransientModel): + _name = "sale.order.line.rma.wizard" + _description = 'Sale Order Line Rma Wizard' + + wizard_id = fields.Many2one( + comodel_name='sale.order.rma.wizard', + string='Wizard', + ) + order_id = fields.Many2one( + comodel_name='sale.order', + default=lambda self: self.env['sale.order'].browse( + self.env.context.get('active_id', False)), + ) + allowed_product_ids = fields.Many2many( + comodel_name='product.product', + compute='_compute_allowed_product_ids' + ) + product_id = fields.Many2one( + comodel_name='product.product', + string='Product', + required=True, + domain="[('id', 'in', allowed_product_ids)]" + ) + uom_category_id = fields.Many2one( + comodel_name='uom.category', + related='product_id.uom_id.category_id', + ) + quantity = fields.Float( + string='Quantity', + digits=dp.get_precision('Product Unit of Measure'), + required=True, + ) + uom_id = fields.Many2one( + comodel_name='uom.uom', + string='Unit of Measure', + domain="[('category_id', '=', uom_category_id)]", + required=True, + ) + allowed_picking_ids = fields.Many2many( + comodel_name='stock.picking', + compute='_compute_allowed_picking_ids' + ) + picking_id = fields.Many2one( + comodel_name='stock.picking', + string='Delivery order', + domain="[('id', 'in', allowed_picking_ids)]" + ) + move_id = fields.Many2one( + comodel_name='stock.move', + compute='_compute_move_id' + ) + operation_id = fields.Many2one( + comodel_name='rma.operation', + string='Requested operation', + ) + + @api.onchange('product_id') + def onchange_product_id(self): + self.picking_id = False + + @api.depends('picking_id') + def _compute_move_id(self): + for record in self: + if record.picking_id: + record.move_id = record.picking_id.move_lines.filtered( + lambda r: (r.sale_line_id.product_id == record.product_id + and r.sale_line_id.order_id == record.order_id)) + + @api.depends('order_id') + def _compute_allowed_product_ids(self): + for record in self: + product_ids = record.order_id.order_line.mapped('product_id.id') + record.allowed_product_ids = product_ids + + @api.depends('product_id') + def _compute_allowed_picking_ids(self): + for record in self: + line = record.order_id.order_line.filtered( + lambda r: r.product_id == record.product_id) + record.allowed_picking_ids = line.mapped('move_ids.picking_id') + + def _prepare_rma_values(self): + self.ensure_one() + return { + 'partner_id': self.order_id.partner_id.id, + 'partner_invoice_id': self.order_id.partner_invoice_id.id, + 'origin': self.order_id.name, + 'company_id': self.order_id.company_id.id, + 'location_id': self.wizard_id.location_id.id, + 'order_id': self.order_id.id, + 'picking_id': self.picking_id.id, + 'move_id': self.move_id.id, + 'product_id': self.product_id.id, + 'product_uom_qty': self.quantity, + 'product_uom': self.uom_id.id, + 'operation_id': self.operation_id.id, + } diff --git a/rma_sale/wizard/sale_order_rma_wizard_views.xml b/rma_sale/wizard/sale_order_rma_wizard_views.xml new file mode 100644 index 00000000..86a3997a --- /dev/null +++ b/rma_sale/wizard/sale_order_rma_wizard_views.xml @@ -0,0 +1,51 @@ + + + + Create RMAs + sale.order.rma.wizard + form + form + new + + + + sale.order.rma.wizard.form + sale.order.rma.wizard + +
+ + + + + + + + + + + + + + + + + + + +
+
+
+