Files
rma/rma_sale/controllers/sale_portal.py
Ernesto Tejeda ea60be4787 [FIX+IMP] rma, rma_sale: fix bugs and add improvements
- Fix thrown error when trying to download a picking from the portal.
- Add the hook method to prepare RMA values ​​from the return pick wizard.
- Add the access rule for portal users.
- Show the portal 'Request RMAs' button on the sales page only to users
related to the sales order.

[UPD] Update rma_sale.pot

rma_sale 12.0.1.3.0

Update translation files

Updated by "Update PO files to match POT (msgmerge)" hook in Weblate.

Translation: rma-12.0/rma-12.0-rma_sale
Translate-URL: https://translation.odoo-community.org/projects/rma-12-0/rma-12-0-rma_sale/
2022-09-20 08:16:11 -04:00

45 lines
1.9 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import http, _
from odoo.exceptions import AccessError, MissingError
from odoo.http import request
from odoo.addons.sale.controllers.portal import CustomerPortal
class CustomerPortal(CustomerPortal):
@http.route(['/my/orders/<int:order_id>/requestrma'], type='http',
auth="public", methods=['POST'], website=True)
def request_rma(self, order_id, access_token=None, **post):
try:
order_sudo = self._document_check_access('sale.order', order_id,
access_token=access_token)
except (AccessError, MissingError):
return request.redirect('/my')
order_obj = request.env['sale.order']
wizard_obj = request.env['sale.order.rma.wizard']
# Set wizard line vals
mapped_vals = {}
for name, value in post.items():
row, field_name = name.split('-', 1)
mapped_vals.setdefault(row, {}).update({field_name: value})
line_vals = [(0, 0, vals) for vals in mapped_vals.values()]
# Create wizard an generate rmas
order = order_obj.browse(order_id).sudo()
location_id = order.warehouse_id.rma_loc_id.id
wizard = wizard_obj.with_context(active_id=order_id).create({
'line_ids': line_vals,
'location_id': location_id
})
rma = wizard.sudo().create_rma(from_portal=True)
for rec in rma:
rec.origin += _(' (Portal)')
# Add the user as follower of the created RMAs so they can
# later view them.
rma.message_subscribe([request.env.user.partner_id.id])
if len(rma) == 0:
route = order_sudo.get_portal_url()
else:
route = "/my/rmas?sale_id=%d" % order_id
return request.redirect(route)