diff --git a/website_rma/__init__.py b/website_rma/__init__.py new file mode 100644 index 00000000..5c2bd8c9 --- /dev/null +++ b/website_rma/__init__.py @@ -0,0 +1,4 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import controllers +from . import models diff --git a/website_rma/__manifest__.py b/website_rma/__manifest__.py new file mode 100644 index 00000000..d3106b8f --- /dev/null +++ b/website_rma/__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 - Website Form", + "summary": "Return Merchandise Authorization (RMA)", + "version": "12.0.1.0.0", + "development_status": "Production/Stable", + "category": "RMA", + "website": "https://github.com/OCA/rma", + "author": "Tecnativa, Odoo Community Association (OCA)", + "maintainers": ["ernestotejeda"], + "license": "AGPL-3", + "depends": [ + "rma", + "website_form", + ], + "data": [ + "data/ir_model_data.xml", + "views/assets.xml", + "views/request_rma_form.xml", + "views/website_rma_portal_templates.xml", + "views/website_templates.xml", + "data/website_data.xml", + ], +} diff --git a/website_rma/controllers/__init__.py b/website_rma/controllers/__init__.py new file mode 100644 index 00000000..f43232f0 --- /dev/null +++ b/website_rma/controllers/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import main diff --git a/website_rma/controllers/main.py b/website_rma/controllers/main.py new file mode 100644 index 00000000..ec16725b --- /dev/null +++ b/website_rma/controllers/main.py @@ -0,0 +1,41 @@ +# Copyright 2020 Tecnativa - Ernesto Tejeda +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +import json +from odoo import http +from odoo.addons.website_form.controllers.main import WebsiteForm +from odoo.http import request + + +class WebsiteForm(WebsiteForm): + + def insert_record(self, request, model, values, custom, meta=None): + if model.model == 'rma': + values['partner_id'] = request.env.user.partner_id.id + return super(WebsiteForm, self).insert_record( + request, model, values, custom, meta=meta) + + +class WebsiteRMA(http.Controller): + + def _get_website_rma_product_domain(self, q): + """Domain used for the products to be shown in selection of + the web form. + """ + return [ + ('name', '=ilike', "%{}%".format(q or '')), + ("sale_ok", "=", True), + ] + + @http.route(['/requestrma'], type='http', auth="user", website=True) + def request_rma(self, **kw): + return http.request.render("website_rma.request_rma", {}) + + @http.route('/website_rma/get_products', type='http', auth="user", + methods=['GET'], website=True) + def rma_product_read(self, q='', l=25, **post): + data = request.env['product.product'].sudo().search_read( + domain=self._get_website_rma_product_domain(q), + fields=['id', 'display_name', 'uom_id'], + limit=int(l), + ) + return json.dumps(data) diff --git a/website_rma/data/ir_model_data.xml b/website_rma/data/ir_model_data.xml new file mode 100644 index 00000000..ab7e9f15 --- /dev/null +++ b/website_rma/data/ir_model_data.xml @@ -0,0 +1,24 @@ + + + + + + + True + Request RMA + + + + rma + + + diff --git a/website_rma/data/website_data.xml b/website_rma/data/website_data.xml new file mode 100644 index 00000000..b7842fc2 --- /dev/null +++ b/website_rma/data/website_data.xml @@ -0,0 +1,13 @@ + + + + + + /requestrma-thank-you + + True + + + + diff --git a/website_rma/i18n/es.po b/website_rma/i18n/es.po new file mode 100644 index 00000000..eccd0a6b --- /dev/null +++ b/website_rma/i18n/es.po @@ -0,0 +1,138 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * website_rma +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2020-09-04 17:22+0000\n" +"PO-Revision-Date: 2020-09-04 13:34-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: website_rma +#: model_terms:ir.ui.view,arch_db:website_rma.request_rma_thanks_page_ir_ui_view +#: model_terms:website.page,arch_db:website_rma.request_rma_thanks_page +msgid "&times;" +msgstr "" + +#. module: website_rma +#: model_terms:ir.ui.view,arch_db:website_rma.request_rma +msgid "Description" +msgstr "Descripción" + +#. module: website_rma +#: model:ir.model,name:website_rma.model_ir_model +msgid "Models" +msgstr "Modelos" + +#. module: website_rma +#: model_terms:ir.ui.view,arch_db:website_rma.request_rma +msgid "Operation" +msgstr "Operación" + +#. module: website_rma +#: model_terms:ir.ui.view,arch_db:website_rma.request_rma +msgid "Our team will process it an will reach you once it's validated." +msgstr "Nuestro equipo lo procesará y le contactará una vez que sea validada." + +#. module: website_rma +#: model_terms:ir.ui.view,arch_db:website_rma.request_rma +msgid "Product" +msgstr "Producto" + +#. module: website_rma +#: model_terms:ir.ui.view,arch_db:website_rma.request_rma +msgid "Quantity" +msgstr "Cantidad" + +#. module: website_rma +#: model_terms:ir.ui.view,arch_db:website_rma.request_rma +msgid "Request" +msgstr "Solicitar" + +#. module: website_rma +#: model_terms:ir.ui.view,arch_db:website_rma.request_rma +#, fuzzy +msgid "Request RMA" +msgstr "Solicitar RMA" + +#. module: website_rma +#: model_terms:ir.ui.view,arch_db:website_rma.request_rma_thanks_page_ir_ui_view +#: model_terms:website.page,arch_db:website_rma.request_rma_thanks_page +msgid "Thanks!" +msgstr "¡Gracias!" + +#. module: website_rma +#: model_terms:ir.ui.view,arch_db:website_rma.request_rma_thanks_page_ir_ui_view +#: model_terms:website.page,arch_db:website_rma.request_rma_thanks_page +msgid "We will get back to you shortly." +msgstr "Le contestaremos en breve." + +#. module: website_rma +#: model_terms:ir.ui.view,arch_db:website_rma.contact_us_request_rma +#: model_terms:ir.ui.view,arch_db:website_rma.portal_my_home_rma +msgid "You can request an RMA" +msgstr "Puede solicitar" + +#. module: website_rma +#: model_terms:ir.ui.view,arch_db:website_rma.request_rma_thanks_page_ir_ui_view +#: model_terms:website.page,arch_db:website_rma.request_rma_thanks_page +msgid "Your request has been sent successfully." +msgstr "Su solicitud ha sido enviada satisfactoriamente." + +#. module: website_rma +#: model_terms:ir.ui.view,arch_db:website_rma.contact_us_request_rma +#: model_terms:ir.ui.view,arch_db:website_rma.portal_my_home_rma +msgid "here" +msgstr "aquí" + +#. module: website_rma +#: model_terms:ir.ui.view,arch_db:website_rma.contact_us_request_rma +msgid "" +"if you do not\n" +" know the sales order from which it was " +"made.\n" +" If you know the sales order, go to it " +"and click on the corresponding button." +msgstr "" + +#. module: website_rma +#: model_terms:ir.ui.view,arch_db:website_rma.portal_my_home_rma +msgid "" +"if you do not\n" +" know the sales order from which it was " +"made. If you know\n" +" the sales order, go to it and click on " +"the corresponding button." +msgstr "" + +#~ msgid "" +#~ "if you do not\n" +#~ " know the sales order from which it was made.\n" +#~ " If you know the sales order, go to it and " +#~ "click on the corresponding button." +#~ msgstr "" +#~ "directamente una devolución si no conoce\n" +#~ " el pedido de venta desde el que se realizó.\n" +#~ " Si conoce el pedido, vaya a él y pulse en el " +#~ "botón correspondiente." + +#~ msgid "" +#~ "if you do not\n" +#~ " know the sales order from which it was made. If you " +#~ "know\n" +#~ " the sales order, go to it and click on the " +#~ "corresponding button." +#~ msgstr "" +#~ "directamente una devolución si no conoce\n" +#~ " el pedido de venta desde el que se realizó.\n" +#~ " Si conoce el pedido, vaya a él y pulse en el " +#~ "botón correspondiente." diff --git a/website_rma/i18n/website_rma.pot b/website_rma/i18n/website_rma.pot new file mode 100644 index 00000000..4bf90dcf --- /dev/null +++ b/website_rma/i18n/website_rma.pot @@ -0,0 +1,105 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * website_rma +# +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: website_rma +#: model_terms:ir.ui.view,arch_db:website_rma.request_rma_thanks_page_ir_ui_view +#: model_terms:website.page,arch_db:website_rma.request_rma_thanks_page +msgid "&times;" +msgstr "" + +#. module: website_rma +#: model_terms:ir.ui.view,arch_db:website_rma.request_rma +msgid "Description" +msgstr "" + +#. module: website_rma +#: model:ir.model,name:website_rma.model_ir_model +msgid "Models" +msgstr "" + +#. module: website_rma +#: model_terms:ir.ui.view,arch_db:website_rma.request_rma +msgid "Operation" +msgstr "" + +#. module: website_rma +#: model_terms:ir.ui.view,arch_db:website_rma.request_rma +msgid "Our team will process it an will reach you once it's validated." +msgstr "" + +#. module: website_rma +#: model_terms:ir.ui.view,arch_db:website_rma.request_rma +msgid "Product" +msgstr "" + +#. module: website_rma +#: model_terms:ir.ui.view,arch_db:website_rma.request_rma +msgid "Quantity" +msgstr "" + +#. module: website_rma +#: model_terms:ir.ui.view,arch_db:website_rma.request_rma +msgid "Request" +msgstr "" + +#. module: website_rma +#: model_terms:ir.ui.view,arch_db:website_rma.request_rma +msgid "Request RMA" +msgstr "" + +#. module: website_rma +#: model_terms:ir.ui.view,arch_db:website_rma.request_rma_thanks_page_ir_ui_view +#: model_terms:website.page,arch_db:website_rma.request_rma_thanks_page +msgid "Thanks!" +msgstr "" + +#. module: website_rma +#: model_terms:ir.ui.view,arch_db:website_rma.request_rma_thanks_page_ir_ui_view +#: model_terms:website.page,arch_db:website_rma.request_rma_thanks_page +msgid "We will get back to you shortly." +msgstr "" + +#. module: website_rma +#: model_terms:ir.ui.view,arch_db:website_rma.contact_us_request_rma +#: model_terms:ir.ui.view,arch_db:website_rma.portal_my_home_rma +msgid "You can request an RMA" +msgstr "" + +#. module: website_rma +#: model_terms:ir.ui.view,arch_db:website_rma.request_rma_thanks_page_ir_ui_view +#: model_terms:website.page,arch_db:website_rma.request_rma_thanks_page +msgid "Your request has been sent successfully." +msgstr "" + +#. module: website_rma +#: model_terms:ir.ui.view,arch_db:website_rma.contact_us_request_rma +#: model_terms:ir.ui.view,arch_db:website_rma.portal_my_home_rma +msgid "here" +msgstr "" + +#. module: website_rma +#: model_terms:ir.ui.view,arch_db:website_rma.contact_us_request_rma +msgid "if you do not\n" +" know the sales order from which it was made.\n" +" If you know the sales order, go to it and click on the corresponding button." +msgstr "" + +#. module: website_rma +#: model_terms:ir.ui.view,arch_db:website_rma.portal_my_home_rma +msgid "if you do not\n" +" know the sales order from which it was made. If you know\n" +" the sales order, go to it and click on the corresponding button." +msgstr "" + diff --git a/website_rma/models/__init__.py b/website_rma/models/__init__.py new file mode 100644 index 00000000..441c8c26 --- /dev/null +++ b/website_rma/models/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import ir_model diff --git a/website_rma/models/ir_model.py b/website_rma/models/ir_model.py new file mode 100644 index 00000000..eb174be7 --- /dev/null +++ b/website_rma/models/ir_model.py @@ -0,0 +1,23 @@ +# Copyright 2020 Tecnativa - Ernesto Tejeda +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import api, models + + +class IrModel(models.Model): + _inherit = 'ir.model' + + @api.model + def get_authorized_fields(self, model_name): + """Hack this method to force some rma fields to be authorized in + creating an object from a web form using the website_form module. + + Those fields are readonly in all states except 'draft' state, + but the main method get_authorized_fields interprets them as + readonly always. + """ + res = super().get_authorized_fields(model_name) + if model_name == 'rma': + auth_fields = ['product_uom_qty', 'product_uom', 'partner_id'] + res.update(self.env[model_name].fields_get(auth_fields)) + return res diff --git a/website_rma/readme/CONTRIBUTORS.rst b/website_rma/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000..d4052271 --- /dev/null +++ b/website_rma/readme/CONTRIBUTORS.rst @@ -0,0 +1,5 @@ +* `Tecnativa `_: + + * Ernesto Tejeda + * Pedro M. Baeza + * David Vidal diff --git a/website_rma/readme/README.rst b/website_rma/readme/README.rst new file mode 100644 index 00000000..0adba71d --- /dev/null +++ b/website_rma/readme/README.rst @@ -0,0 +1,2 @@ +This module extends the functionality of rma and website to allow you +to request an RMA through a form in the website. diff --git a/website_rma/readme/USAGE.rst b/website_rma/readme/USAGE.rst new file mode 100644 index 00000000..90e8aebe --- /dev/null +++ b/website_rma/readme/USAGE.rst @@ -0,0 +1,12 @@ +To use this module, you need to: + +#. Go to the website +#. Go to *Your username (at the upper-right corner) > My account* or + access to /my (Example: https://www.odoo.com/my). +#. Under your documents list you can see a text with a link to the page + where you can create an RMA through a form. +#. Click on this link to access to this page or access to + /requestrma (Example: https://www.odoo.com/requestrma). +#. Fill the desired and required fields and click on the button 'Request'. +#. If everything is right, a new RMA document will created, you will be + redirected to a page with a thank you message. diff --git a/website_rma/static/description/icon.png b/website_rma/static/description/icon.png new file mode 100644 index 00000000..3a0328b5 Binary files /dev/null and b/website_rma/static/description/icon.png differ diff --git a/website_rma/static/src/js/website_rma.js b/website_rma/static/src/js/website_rma.js new file mode 100644 index 00000000..2785b214 --- /dev/null +++ b/website_rma/static/src/js/website_rma.js @@ -0,0 +1,45 @@ +/* Copyright 2020 Tecnativa - Ernesto Tejeda +/* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + */ +odoo.define('website_rma.website_rma', function(require) { + "use strict"; + + require('web.dom_ready'); + + $("#rma_request_form input[name='product_id']").select2({ + width: '100%', + placeholder: 'Select a product', + allowClear: true, + selection_data: false, + ajax: { + url: '/website_rma/get_products', + dataType: 'json', + data: function(term) { + return { + q: term, + l: 50 + }; + }, + results: function(data) { + var res = []; + _.each(data, function(x) { + res.push({ + id: x.id, + text: x.display_name, + uom_id: x.uom_id[0], + uom_name: x.uom_id[1] + }); + }); + return {results: res}; + } + }, + }); + // Set UoM on selected onchange + $("#rma_request_form input[name='product_id']").change(function(){ + var select2_data = $(this).select2('data'); + var uom_id = select2_data ? select2_data['uom_id'] : '' + var uom_name = select2_data ? select2_data['uom_name'] : '' + $("input[name='product_uom']").val(uom_id); + $("input[name='product_uom_name']").val(uom_name); + }); +}); diff --git a/website_rma/static/src/js/website_rma.tour.js b/website_rma/static/src/js/website_rma.tour.js new file mode 100644 index 00000000..56ba399f --- /dev/null +++ b/website_rma/static/src/js/website_rma.tour.js @@ -0,0 +1,45 @@ +/* Copyright 2020 Tecnativa - Ernesto Tejeda +/* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + */ +odoo.define('website_sale_vat_required.tour', function(require) { + "use strict"; + + var tour = require("web_tour.tour"); + var base = require("web_editor.base"); + + tour.register("request_rma", + { + test: true, + url: "/my", + wait_for: base.ready() + }, + [ + { + content: "Click on RMA form page link", + trigger: ".o_portal_my_home a[href='/requestrma']", + }, + { + content: 'Click on request button with the form empty', + trigger: "a.o_website_form_send", + }, + { + content: 'Fill form', + trigger: "#rma_request_form", + extra_trigger: "#rma_request_form", + run: function (actions) { + $("select[name='operation_id'] > option:eq(1)").prop('selected', true); + $("textarea[name='description']").val("RMA test from website form"); + + } + }, + { + content: 'Click on request button with the form empty', + trigger: "a.o_website_form_send", + }, + { + content: "Click on RMA form page link", + trigger: "div#request_rma_thanks", + } + ] + ) +}); diff --git a/website_rma/tests/__init__.py b/website_rma/tests/__init__.py new file mode 100644 index 00000000..b49733c8 --- /dev/null +++ b/website_rma/tests/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import test_website_rma diff --git a/website_rma/tests/test_website_rma.py b/website_rma/tests/test_website_rma.py new file mode 100644 index 00000000..eea806f4 --- /dev/null +++ b/website_rma/tests/test_website_rma.py @@ -0,0 +1,51 @@ +# Copyright 2020 Tecnativa - Ernesto Tejeda +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo.tests.common import Form, HttpCase + + +class TestWebsiteRma(HttpCase): + + def setUp(self): + super().setUp() + self.product = self.env['product.product'].create({ + 'name': 'Website rma 1', + 'type': 'product', + }) + picking_type = self.env['stock.picking.type'].search( + [ + ('code', '=', 'outgoing'), + '|', + ('warehouse_id.company_id', '=', self.env.user.company_id.id), + ('warehouse_id', '=', False) + ], + limit=1, + ) + picking_form = Form( + recordp=self.env['stock.picking'].with_context( + default_picking_type_id=picking_type.id), + view="stock.view_picking_form", + ) + picking_form.partner_id = self.env.user.partner_id + with picking_form.move_ids_without_package.new() as move: + move.product_id = self.product + move.product_uom_qty = 10 + picking = picking_form.save() + picking.action_confirm() + picking.move_lines.quantity_done = 10 + picking.button_validate() + + def test_website_form_request_rma(self): + self.browser_js( + url_path="/my", + code="odoo.__DEBUG__.services['web_tour.tour']" + ".run('request_rma')", + ready="odoo.__DEBUG__.services['web_tour.tour']" + ".tours.request_rma.ready", + login="admin", + ) + rma = self.env['rma'].search([ + ('operation_id', '!=', False), + ('description', '=', "RMA test from website form"), + ]) + self.assertTrue(bool(rma)) diff --git a/website_rma/views/assets.xml b/website_rma/views/assets.xml new file mode 100644 index 00000000..ab0bedbe --- /dev/null +++ b/website_rma/views/assets.xml @@ -0,0 +1,11 @@ + + + + + diff --git a/website_rma/views/request_rma_form.xml b/website_rma/views/request_rma_form.xml new file mode 100644 index 00000000..82c29d06 --- /dev/null +++ b/website_rma/views/request_rma_form.xml @@ -0,0 +1,148 @@ + + + + + + + + Thanks (Request RMA) + qweb + website_rma.requestrma_thanks + + + +
+
+
+

Thanks!

+
+
+
+ Your request has been sent successfully. + +
+

+ We will get back to you shortly. +

+
+
+ +
+
+
+
+
+ + + + + diff --git a/website_rma/views/website_rma_portal_templates.xml b/website_rma/views/website_rma_portal_templates.xml new file mode 100644 index 00000000..a07c39e9 --- /dev/null +++ b/website_rma/views/website_rma_portal_templates.xml @@ -0,0 +1,24 @@ + + + + + diff --git a/website_rma/views/website_templates.xml b/website_rma/views/website_templates.xml new file mode 100644 index 00000000..cfb31e6a --- /dev/null +++ b/website_rma/views/website_templates.xml @@ -0,0 +1,24 @@ + + + + +