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


Now I am extending the new field (boolean) to the object, sale.order.

My default value of extended field is False.

Extending part is ok and I already added this field to tree, form view.

So my original idea is when user press "add to cart" button in webshop, my new extended field automatically assign true (boolean) value. In Odoo, adding cart is like creating new Quotation in back-end if Quotation haven't created yet.

Here is my extended field:

from odoo import api, fields, models

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

   is_value_over = fields.Boolean(string='value_over')

I just realized that I needed to assign this value in two main functions under website_sale module, as below:

 @http.route(['/shop/cart'], type='http', auth="public", website=True)
def cart(self, **post):

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

How can I assign is_value_over value to true when user is adding item to the cart?


Imagine profil
Abandonează
Cel mai bun răspuns

in my case

from odoo.addons.website_sale.controllers.main import WebsiteSale

class PresaleAndFinancing(WebsiteSale):

@http.route(['/shop/cart/update/presale'], type='json', auth="public", methods=['POST'], website=True)
def cart_update_multi_variant(self,data,**post):
data = data[0] # ignore
month_qty = data['presale'] + data['financing'] #i gnore
# update the cart (native method, create and validate the order if necessary)
self.cart_update(
product_id = data['product_id'], // if of product, check other values in my case not necesary
)
# get the obj of order actual
order = request.website.sale_get_order()
# update the new field created in sale.order
order.sudo().write({'month_qty': month_qty})
Imagine profil
Abandonează
Cel mai bun răspuns

If you change the class definition line in your extension code from

class add_to_cart_extend(models.Model):

to

class SaleOrder(models.Model):

the base SaleOrder class will be extended and the new field will be added to the sale.order model. You can then set its value just like all the other fields available in the model.

Imagine profil
Abandonează
Related Posts Răspunsuri Vizualizări Activitate
1
dec. 24
2337
1
apr. 25
2564
0
oct. 22
2389
4
sept. 15
6161
1
sept. 24
1524