跳至内容
菜单
此问题已终结
2 回复
4238 查看


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.

形象
丢弃
相关帖文 回复 查看 活动
1
12月 24
2315
1
4月 25
2563
0
10月 22
2374
4
9月 15
6157
1
9月 24
1521