From f4affc0422b1c31b483d85c9bd93b94e8f0de338 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Mart=C3=ADnez?= Date: Mon, 16 May 2022 18:14:50 +0200 Subject: [PATCH] =?UTF-8?q?[FIX]=20rma=20+=20rma=5Fsale:=20Allow=20to=20cr?= =?UTF-8?q?eate=20an=20RMA=20to=20a=20user=20with=20access=5Fto=E2=80=A6ke?= =?UTF-8?q?n=20to=20sale=20order=20(no=20user=20created).=20[FIX]=20rma=20?= =?UTF-8?q?+=20rma=5Fsale:=20Show=20RMA's=20list=20(with=20share=20url)=20?= =?UTF-8?q?to=20a=20user=20with=20access=5Ftoken=20to=20sale=20order=20(no?= =?UTF-8?q?=20user=20created).?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rma/models/rma.py | 7 +++++-- rma_sale/controllers/sale_portal.py | 12 +++++++++++- rma_sale/views/sale_portal_template.xml | 2 +- rma_sale/wizard/sale_order_rma_wizard.py | 17 ++++++++++++++--- 4 files changed, 31 insertions(+), 7 deletions(-) diff --git a/rma/models/rma.py b/rma/models/rma.py index 29d59104..bc82a99f 100644 --- a/rma/models/rma.py +++ b/rma/models/rma.py @@ -623,6 +623,10 @@ class Rma(models.Model): "context": ctx, } + def _add_message_subscribe_partner(self): + if self.partner_id and self.partner_id not in self.message_partner_ids: + self.message_subscribe([self.partner_id.id]) + def action_confirm(self): """Invoked when 'Confirm' button in rma form view is clicked.""" self.ensure_one() @@ -633,8 +637,7 @@ class Rma(models.Model): else: reception_move = self._create_receptions_from_product() self.write({"reception_move_id": reception_move.id, "state": "confirmed"}) - if self.partner_id not in self.message_partner_ids: - self.message_subscribe([self.partner_id.id]) + self._add_message_subscribe_partner() self._send_confirmation_email() def action_refund(self): diff --git a/rma_sale/controllers/sale_portal.py b/rma_sale/controllers/sale_portal.py index 967e12e4..50a7d51d 100644 --- a/rma_sale/controllers/sale_portal.py +++ b/rma_sale/controllers/sale_portal.py @@ -1,4 +1,5 @@ # Copyright 2020 Tecnativa - Ernesto Tejeda +# Copyright 2022 Tecnativa - Víctor Martínez # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). from odoo import _, http @@ -64,6 +65,9 @@ class CustomerPortal(CustomerPortal): "custom_description": custom_description, } ) + user_has_group_portal = request.env.user.has_group( + "base.group_portal" + ) or request.env.user.has_group("base.group_public") rma = wizard.sudo().create_rma(from_portal=True) for rec in rma: rec.origin += _(" (Portal)") @@ -76,8 +80,14 @@ class CustomerPortal(CustomerPortal): ).subtype_ids += request.env.ref("rma.mt_rma_notification") if len(rma) == 0: route = order_sudo.get_portal_url() + elif len(rma) == 1: + route = rma._get_share_url() if user_has_group_portal else rma.access_url else: - route = "/my/rmas?sale_id=%d" % order_id + route = ( + order._get_share_url() + if user_has_group_portal + else "/my/rmas?sale_id=%d" % order_id + ) return request.redirect(route) @http.route( diff --git a/rma_sale/views/sale_portal_template.xml b/rma_sale/views/sale_portal_template.xml index 0150d4ab..dcac93a9 100644 --- a/rma_sale/views/sale_portal_template.xml +++ b/rma_sale/views/sale_portal_template.xml @@ -4,7 +4,7 @@
diff --git a/rma_sale/wizard/sale_order_rma_wizard.py b/rma_sale/wizard/sale_order_rma_wizard.py index baac18a2..04c30cdf 100644 --- a/rma_sale/wizard/sale_order_rma_wizard.py +++ b/rma_sale/wizard/sale_order_rma_wizard.py @@ -1,7 +1,8 @@ # Copyright 2020 Tecnativa - Ernesto Tejeda +# Copyright 2022 Tecnativa - Víctor Martínez # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -from odoo import _, api, fields, models +from odoo import SUPERUSER_ID, _, api, fields, models class SaleOrderRmaWizard(models.TransientModel): @@ -46,11 +47,21 @@ class SaleOrderRmaWizard(models.TransientModel): help="Values coming from portal RMA request form custom fields", ) - def create_rma(self, from_portal=None): + def create_rma(self, from_portal=False): self.ensure_one() + user_has_group_portal = self.env.user.has_group( + "base.group_portal" + ) or self.env.user.has_group("base.group_public") lines = self.line_ids.filtered(lambda r: r.quantity > 0.0) val_list = [line._prepare_rma_values() for line in lines] - rma = self.env["rma"].create(val_list) + rma_model = ( + self.env["rma"].with_user(SUPERUSER_ID) + if user_has_group_portal + else self.env["rma"] + ) + rma = rma_model.create(val_list) + if from_portal: + rma._add_message_subscribe_partner() # post messages msg_list = [ '%s' % (r.id, r.name)