| 1 |
# Part of Odoo. See LICENSE file for full copyright and licensing details. |
| 2 |
|
| 3 |
from odoo.exceptions import AccessError, MissingError |
| 4 |
from odoo.http import request, route |
| 5 |
|
| 6 |
from odoo.addons.sale.controllers import portal |
| 7 |
|
| 8 |
|
| 9 |
class CustomerPortal(portal.CustomerPortal): |
| 10 |
|
| 11 |
@route(['/my/orders/<int:order_id>/update_line_dict'], type='jsonrpc', auth="public", website=True) |
| 12 |
def portal_quote_option_update(self, order_id, line_id, access_token=None, remove=False, input_quantity=False, **kwargs): |
| 13 |
""" Update the quantity of an optional SOline from a SO. |
| 14 |
|
| 15 |
:param int order_id: `sale.order` id |
| 16 |
:param int line_id: `sale.order.line` id |
| 17 |
:param str access_token: portal access_token of the specified order |
| 18 |
:param bool remove: if true, 1 unit will be removed from the line |
| 19 |
:param float input_quantity: if specified, will be set as new line qty |
| 20 |
:param dict kwargs: unused parameters |
| 21 |
""" |
| 22 |
try: |
| 23 |
order_sudo = self._document_check_access('sale.order', order_id, access_token=access_token) |
| 24 |
except (AccessError, MissingError): |
| 25 |
return request.redirect('/my') |
| 26 |
|
| 27 |
# Redundant with can be edited on portal for line, ask sales if can rbe removed |
| 28 |
if not order_sudo._can_be_edited_on_portal(): |
| 29 |
return |
| 30 |
|
| 31 |
order_line = request.env['sale.order.line'].sudo().browse(int(line_id)).exists() |
| 32 |
if ( |
| 33 |
not order_line |
| 34 |
or order_line.order_id != order_sudo |
| 35 |
or not order_line._can_be_edited_on_portal() |
| 36 |
): |
| 37 |
# Do not allow updating non-optional lines from a quotation |
| 38 |
return |
| 39 |
|
| 40 |
if input_quantity is not False: |
| 41 |
quantity = input_quantity |
| 42 |
else: |
| 43 |
number = -1 if remove else 1 |
| 44 |
quantity = max((order_line.product_uom_qty + number), 0) |
| 45 |
|
| 46 |
if order_line.product_type == 'combo': |
| 47 |
# for combo products, we update the quantities of the combo items too |
| 48 |
combo_item_lines = order_line._get_linked_lines().filtered('combo_item_id') |
| 49 |
combo_item_lines.update({'product_uom_qty': quantity}) |
| 50 |
|
| 51 |
order_line.product_uom_qty = quantity |