I have migrated my module from ver 12 to 13 but still I am unable to get the concept of two functions which is (init_from_json) and (export_as_json). I have a combo pack module. When I select a combo pack deal first time it works fine in the POS orderline but when I change the table1 to table2 and coming back to table1 from table2 the combopack deal product are appearing as a single product or individual product and it is working fine in v12. If i am seeing it into the console the POS orderline is reinitializing everytime when i click on the POS table. I am getting stuck at this stage. Your response will be appreciated. Here is my orderline code.
var _super_order_line = models.Orderline.prototype;
models.Orderline = models.Orderline.extend({
init_from_JSON: function(json) {
_super_order_line.init_from_JSON.call(this, json);
var self = this
if(json.is_pack){
this.pack_data = []
_.each(json.combo_ids, function(item){
item = item[2]
self.pack_data.push({
'product_id':self.pos.db.get_product_by_id(item.product_id),
'qty':item.qty * json.qty,
});
})
}
if(json.is_extra){
this.order_menu = json.order_menu
}
},
export_as_JSON: function(){
var self = this;
var own_line = [];
var total_price = 0;
var json = _super_order_line.export_as_JSON.apply(this, arguments);
console.log('EXPORT AS JSON: ', json);
if(this.product.is_extra && this.own_data){
_.each(this.own_data, function(item){
own_line.push([0, 0, {'product_id':item.product_id.id,
'name':item.product_id,
'qty':self.get_quantity(),
'price':item.price,
'price_subtotal_incl':0.0,
'price_subtotal':0.0,
}]);
total_price += item.price;
});
json.order_menu = this.order_menu
}
if (this.product.is_extra){
json.price_unit = total_price;
}
json.price_unit = this.price;
json.is_extra = this.product.is_extra;
json.own_ids = this.product.is_extra ? own_line : [];
var combo_line = []
if(self.product.is_pack && self.pack_data){
console.log('self.pack_data', self.pack_data)
_.each(self.pack_data, function(item){
combo_line.push([0, 0, {
'product_id':item.product_id.id,
'name':item.product_id,
'qty':item.qty * self.get_quantity(),
'price_subtotal_incl':0.0,
'price_subtotal':0.0,
}]);
})
}
console.log(combo_line);
json.is_pack = this.product.is_pack;
json.combo_ids = this.product.is_pack ? combo_line : [];
return json;
},
});