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 @@