This question has been flagged

Hello guys,
I want to use the Order Ref (auto generated when order created in python) as the Receipt Reference (that are generated from the java-script and pass to python when order is created). I notice that the Order Ref is generated automatically in python after the order create so how can the java-script get those value... The main purpose of mind is to use the Order Ref as the Receipt Reference that can be print when the order is create in POS. My POS will use in many difference location connected to the same system, so I have use the Order Sequence, so output of my Oder Ref in each location will have the incremental number of it own location. Example: Restaurant17/0012. and the output of my Receipt Reference is the number that generated by java-script. Example: Order 00017-006-0006

Avatar
Discard
Best Answer
//try something like this


odoo.define('pos_extend', function(require) {
"use strict";
var models = require('point_of_sale.models');
var rpc = require('web.rpc');
var screens = require('point_of_sale.screens');
var OrderSuper = models.Order;
models.Order = models.Order.extend({
export_for_printing: function(){
//tasos add order_ref to receipt
var result = OrderSuper.prototype.export_for_printing.call(this);
result.order_ref = this.order_ref;
return result;
},
});




models.PosModel = models.PosModel.extend({

push_order: function(order, opts) {
opts = opts || {};
var self = this;
if(order){
this.db.add_order(order.export_as_JSON());
}
var pushed = new $.Deferred();

this.flush_mutex.exec(function(){
var flushed = self._flush_orders(self.db.get_orders(), opts);
flushed.always(function(ids){
//tasos get order_ref from server
if(order){
rpc.query({
model: 'pos.order',
method: 'search_read',
domain: [['pos_reference', '=', order.name]],
fields: ['name'],
limit: 1,
})
.then(function(data)
{
if(data.length > 0){
order.order_ref = data[0].name;
pushed.resolve();
}
});
}
else{
pushed.resolve();
}

});
return flushed;
});
return pushed;
},
});

screens.PaymentScreenWidget.include({
finalize_validation: function() {
var self = this;
var order = this.pos.get_order();
if (order.is_paid_with_cash() && this.pos.config.iface_cashdrawer) {
this.pos.proxy.open_cashbox();
}
order.initialize_validation_date();
order.finalized = true;
if (order.is_to_invoice()) {
var invoiced = this.pos.push_and_invoice_order(order);
this.invoicing = true;
invoiced.fail(function(error){
self.invoicing = false;
order.finalized = false;
if (error.message === 'Missing Customer') {
self.gui.show_popup('confirm',{
'title': _t('Please select the Customer'),
'body': _t('You need to select the customer before you can invoice an order.'),
confirm: function(){
self.gui.show_screen('clientlist');
},
});
} else if (error.message === 'Backend Invoice') {
self.gui.show_popup('confirm',{
'title': _t('Please print the invoice from the backend'),
'body': _t('The order has been synchronized earlier. Please make the invoice from the backend for the order: ') + error.data.order.name,
confirm: function () {
this.gui.show_screen('receipt');
},
cancel: function () {
this.gui.show_screen('receipt');
},
});
} else if (error.code < 0) { // XmlHttpRequest Errors
self.gui.show_popup('error',{
'title': _t('The order could not be sent'),
'body': _t('Check your internet connection and try again.'),
});
} else if (error.code === 200) { // OpenERP Server Errors
self.gui.show_popup('error-traceback',{
'title': error.data.message || _t("Server Error"),
'body': error.data.debug || _t('The server encountered an error while receiving your order.'),
});
} else { // ???
self.gui.show_popup('error',{
'title': _t("Unknown Error"),
'body': _t("The order could not be sent to the server due to an unknown error"),
});
}
});
invoiced.done(function(){
self.invoicing = false;
self.gui.show_screen('receipt');
});
} else {
var self = this;
//tasos to be synchronous
this.pos.push_order(order).then(function() {
self.gui.show_screen('receipt');
});
}
},
});
});
Avatar
Discard