我试图在pos订单行中添加一个新字段,并在按钮单击中更新值。
pos.oerder.line.py
class pos_order_line(models.Model):
_inherit = 'pos.order.line'
is_promo = fields.Boolean(string='Promo',default=False)
*。js
models.Orderline = models.Orderline.extend({
initialize: function() {
_super_orderline.initialize.apply(this,arguments);
this.is_promo = false;
},
// Help me to understand this function
export_as_JSON: function(){
var json = _super_orderline.export_as_JSON.apply(this,arguments);
json.is_promo = this.is_promo;
return json;
},
// Help me to understand this function
init_from_JSON: function(json){
_super_orderline.init_from_JSON.apply(this,arguments);
this.is_promo = json.is_promo;
},
});
var OfferButton = screens.ActionButtonWidget.extend({
'template': 'PromotioanlButton',
button_click: function(){
var self = this;
self.get_promo_config();
},
get_promo_config: function () {
var self = this;
var order = this.pos.get_order();
var orderline = order.get_orderlines();
var order_product_ids = []
_.each(orderline,function(line){
order_product_ids.push({'product_id':line.product.id,'qty':line.quantity});
});
rpc.query({
model:'promo.config',
method:'check_promo_offer',
args :[order_product_ids],
}).then(function(product_ids){
_.each(product_ids, function(pid){
var product = self.pos.db.get_product_by_id(pid.product_id);
**// I added new item into cart using below code and its working fine.
//It add all the fields below mention except `is_promo`, i mean it still false.
//how can i make it true.**
order.add_product(product, { price:0.0 ,quantity:pid.product_uom_qty,discount:25,is_promo:true,merge:false});
});
});
},
});