Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
1 Răspunde
1997 Vizualizări

Hi,


I'm able to add my custom form elements to cart like the screenshot below: 

https://pasteboard.co/ikyZ5uPfsj1y.png


My question is: How to override the original product price (adding it manually) and display the new price in the cart using the above screenshot price field?

Imagine profil
Abandonează
Cel mai bun răspuns

Hi,

Create a controller for the button submit

do this in the controller

order = request.website.sale_get_order(force_create=True)
values = order._cart_update(
product_id=product_id,
add_qty=add_qty,
set_qty=set_qty,
unit_price=unit_price,
)

now inherit sale.order and add the code below

def _prepare_order_line_update_values(
self, order_line, quantity, linked_line_id=False, **kwargs
):

values = super()._prepare_order_line_update_values(order_line, quantity, linked_line_id, **kwargs)
if 'unit_price' in kwargs:
values["unit_price"] = kwargs.get('unit_price')
return values

Regards

Imagine profil
Abandonează
Autor

Hi,

After inheriting and adding your code in WebsiteSale controller , I get the following error message: name 'unit_price' is not defined. I can't figure what is wrong. Below is the code:

class WebsiteSaleInherit(WebsiteSale):
@http.route(['/shop/cart/update'], type='http', auth="public", methods=['POST'], website=True, csrf=False)
def cart_update(self, product_id, add_qty=1, set_qty=0, **kw):
res = super(WebsiteSaleInherit, self).cart_update(product_id, add_qty=1, set_qty=0, **kw)
order = request.website.sale_get_order(force_create=True)
values = order._cart_update(
product_id=product_id,
add_qty=add_qty,
set_qty=set_qty,
unit_price=unit_price,
)
return res

class SaleOrder(models.Model):
_inherit = 'sale.order'

def _prepare_order_line_update_values(self, order_line, quantity, linked_line_id=False, **kwargs):
values = super()._prepare_order_line_update_values(order_line, quantity, linked_line_id, **kwargs)
if 'unit_price' in kwargs:
values["unit_price"] = kwargs.get('unit_price')
return values

Thanks for helping out.

Hi Cybrosys,
I'm using Odoo v17.
I have a problem after updating the cart amount. When I go to check out and confirm order the price is recalculated by the function "_compute_price". How can I override this function with my customized price? I would appreciate any help from you.

Related Posts Răspunsuri Vizualizări Activitate
1
apr. 23
2486
3
mai 19
6274
0
oct. 22
659
0
oct. 22
379
1
iul. 20
4373