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)