[FIX] rma + rma_sale: Allow to create an RMA to a user with access_to…ken to sale order (no user created).

[FIX] rma + rma_sale: Show RMA's list (with share url) to a user with access_token to sale order (no user created).
This commit is contained in:
Víctor Martínez
2022-05-16 18:14:50 +02:00
committed by Pedro M. Baeza
parent a95e14c6f9
commit f4affc0422
4 changed files with 31 additions and 7 deletions

View File

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

View File

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

View File

@@ -4,7 +4,7 @@
<form
id="form-request-rma"
method="POST"
t-attf-action="/my/orders/#{sale_order.id}/requestrma?access_token=#{sale_order.access_token}"
t-attf-action="/my/orders/#{sale_order.id}/requestrma?{{ keep_query() }}"
t-att-class="not single_page_mode and 'modal-content' or 'col-12'"
>
<input type="hidden" name="csrf_token" t-att-value="request.csrf_token()" />

View File

@@ -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 = [
'<a href="#" data-oe-model="rma" data-oe-id="%d">%s</a>' % (r.id, r.name)