diff --git a/rma_sale/__manifest__.py b/rma_sale/__manifest__.py index 75752cc6..fb3af4cf 100644 --- a/rma_sale/__manifest__.py +++ b/rma_sale/__manifest__.py @@ -17,6 +17,7 @@ "views/rma_views.xml", "views/sale_views.xml", "views/sale_portal_template.xml", + "views/res_config_settings_views.xml", "wizard/sale_order_rma_wizard_views.xml", ], } diff --git a/rma_sale/controllers/sale_portal.py b/rma_sale/controllers/sale_portal.py index e8eec8e6..eb5ab385 100644 --- a/rma_sale/controllers/sale_portal.py +++ b/rma_sale/controllers/sale_portal.py @@ -30,12 +30,18 @@ class CustomerPortal(CustomerPortal): } # Set wizard line vals mapped_vals = {} + custom_vals = {} partner_shipping_id = post.pop("partner_shipping_id", False) for name, value in post.items(): - row, field_name = name.split("-", 1) - if wizard_line_field_types.get(field_name) == "many2one": - value = int(value) if value else False - mapped_vals.setdefault(row, {}).update({field_name: value}) + try: + row, field_name = name.split("-", 1) + if wizard_line_field_types.get(field_name) == "many2one": + value = int(value) if value else False + mapped_vals.setdefault(row, {}).update({field_name: value}) + # Catch possible form custom fields to add them to the RMA + # description values + except ValueError: + custom_vals.update({name: value}) # If no operation is filled, no RMA will be created line_vals = [ (0, 0, vals) for vals in mapped_vals.values() if vals.get("operation_id") @@ -43,11 +49,19 @@ class CustomerPortal(CustomerPortal): # Create wizard an generate rmas order = order_obj.browse(order_id).sudo() location_id = order.warehouse_id.rma_loc_id.id + # Add custom fields text + custom_description = "" + if custom_vals: + custom_description = r"
---
" + custom_description += r"
".join( + ["{}: {}".format(x, y) for x, y in custom_vals.items()] + ) wizard = wizard_obj.with_context(active_id=order_id).create( { "line_ids": line_vals, "location_id": location_id, "partner_shipping_id": partner_shipping_id, + "custom_description": custom_description, } ) rma = wizard.sudo().create_rma(from_portal=True) @@ -61,3 +75,27 @@ class CustomerPortal(CustomerPortal): else: route = "/my/rmas?sale_id=%d" % order_id return request.redirect(route) + + @http.route( + ["/my/requestrma/"], type="http", auth="public", website=True + ) + def request_sale_rma(self, order_id, access_token=None, **kw): + """Request RMA on a single page""" + try: + order_sudo = self._document_check_access( + "sale.order", order_id, access_token=access_token + ) + except (AccessError, MissingError): + return request.redirect("/my") + if order_sudo.state in ("draft", "sent", "cancel"): + return request.redirect("/my") + values = { + "sale_order": order_sudo, + "page_name": "request_rma", + "default_url": order_sudo.get_portal_url(), + "token": access_token, + "partner_id": order_sudo.partner_id.id, + } + if order_sudo.company_id: + values["res_company"] = order_sudo.company_id + return request.render("rma_sale.request_rma_single_page", values) diff --git a/rma_sale/models/__init__.py b/rma_sale/models/__init__.py index 0090dd37..16972d9b 100644 --- a/rma_sale/models/__init__.py +++ b/rma_sale/models/__init__.py @@ -1,5 +1,6 @@ # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). - +from . import res_company +from . import res_config_settings from . import rma from . import sale from . import stock_move diff --git a/rma_sale/models/res_company.py b/rma_sale/models/res_company.py new file mode 100644 index 00000000..021eea2c --- /dev/null +++ b/rma_sale/models/res_company.py @@ -0,0 +1,13 @@ +# Copyright 2021 Tecnativa - David Vidal +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo import fields, models + + +class ResCompany(models.Model): + _inherit = "res.company" + + show_full_page_sale_rma = fields.Boolean( + string="Full page RMA creation", + help="From the frontend sale order page go to a single RMA page " + "creation instead of the usual popup", + ) diff --git a/rma_sale/models/res_config_settings.py b/rma_sale/models/res_config_settings.py new file mode 100644 index 00000000..dd42c753 --- /dev/null +++ b/rma_sale/models/res_config_settings.py @@ -0,0 +1,11 @@ +# Copyright 2021 Tecnativa - David Vidal +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo import fields, models + + +class ResConfigSettings(models.TransientModel): + _inherit = "res.config.settings" + + show_full_page_sale_rma = fields.Boolean( + related="company_id.show_full_page_sale_rma", readonly=False, + ) diff --git a/rma_sale/views/res_config_settings_views.xml b/rma_sale/views/res_config_settings_views.xml new file mode 100644 index 00000000..61618781 --- /dev/null +++ b/rma_sale/views/res_config_settings_views.xml @@ -0,0 +1,36 @@ + + + + res.config.settings + + + +
+
+ +
+
+
+
+
+
+
+
diff --git a/rma_sale/views/sale_portal_template.xml b/rma_sale/views/sale_portal_template.xml index 78de3dc4..0150d4ab 100644 --- a/rma_sale/views/sale_portal_template.xml +++ b/rma_sale/views/sale_portal_template.xml @@ -1,4 +1,194 @@ + +