Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
2 ตอบกลับ
4231 มุมมอง


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?


อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

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})
อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

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.

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
1
ธ.ค. 24
2303
1
เม.ย. 25
2562
0
ต.ค. 22
2368
4
ก.ย. 15
6157
1
ก.ย. 24
1519