Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
4246 Lượt xem


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?


Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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})
Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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.

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 12 24
2324
1
thg 4 25
2564
0
thg 10 22
2378
4
thg 9 15
6159
1
thg 9 24
1523