[IMP] point_of_sale: printing via proxy
bzr revid: fva@openerp.com-20120703140315-xnvioeiner7tz88i
This commit is contained in:
parent
0e255c2b90
commit
116c671d17
|
@ -160,45 +160,44 @@ function openerp_pos_devices(instance,module){ //module is instance.point_of_sal
|
|||
this.message('open_cashbox');
|
||||
},
|
||||
|
||||
// ask the printer to print a receipt
|
||||
/* ask the printer to print a receipt
|
||||
* receipt is a JSON object with the following specs:
|
||||
* receipt{
|
||||
* - orderlines : list of orderlines :
|
||||
* {
|
||||
* quantity: (number) the number of items, or the weight,
|
||||
* unit_name: (string) the name of the item's unit (kg, dozen, ...)
|
||||
* list_price: (number) the price of one unit of the item before discount
|
||||
* discount: (number) the discount on the product in % [0,100]
|
||||
* product_name: (string) the name of the product
|
||||
* price_with_tax: (number) the price paid for this orderline, tax included
|
||||
* price_without_tax: (number) the price paid for this orderline, without taxes
|
||||
* tax: (number) the price paid in taxes on this orderline
|
||||
* }
|
||||
* - paymentlines : list of paymentlines :
|
||||
* {
|
||||
* amount: (number) the amount paid
|
||||
* journal: (string) the name of the journal on wich the payment has been made
|
||||
* }
|
||||
* - total_with_tax: (number) the total of the receipt tax included
|
||||
* - total_without_tax: (number) the total of the receipt without taxes
|
||||
* - total_tax: (number) the total amount of taxes paid
|
||||
* - total_paid: (number) the total sum paid by the client
|
||||
* - change: (number) the amount of change given back to the client
|
||||
* - name: (string) a unique name for this order
|
||||
* - client: (string) name of the client. or null if no client is logged
|
||||
* - cashier: (string) the name of the cashier
|
||||
* - date: { the date at wich the payment has been done
|
||||
* year: (number) the year [2012, ...]
|
||||
* month: (number) the month [0,11]
|
||||
* date: (number) the day of the month [1,31]
|
||||
* day: (number) the day of the week [0,6]
|
||||
* hour: (number) the hour [0,23]
|
||||
* minute: (number) the minute [0,59]
|
||||
* }
|
||||
*/
|
||||
print_receipt: function(receipt){
|
||||
var sample_receipt = {
|
||||
// TODO This is a sample receipt,
|
||||
// we need to discuss the exact format based on what really needs
|
||||
// to be printed on the receipt ...
|
||||
// ... the same for invoices ...
|
||||
client_name: 'John Smith',
|
||||
cashier_name: 'Mike Doe',
|
||||
date: '28 january 2024, 17h32',
|
||||
currency:{
|
||||
symbol: '$',
|
||||
position: 'before',
|
||||
},
|
||||
total_with_taxes: 94.1,
|
||||
total_without_taxes: 90,
|
||||
taxes: 4.1,
|
||||
orderlines:[
|
||||
{
|
||||
name: 'Cola',
|
||||
unit_price_with_taxes: 1,
|
||||
unit_price_without_taxes: 0.8,
|
||||
total_price_with_taxes: 10,
|
||||
total_price_without_taxes: 8,
|
||||
quantity: '10 Bottles',
|
||||
discount: '',
|
||||
},
|
||||
{
|
||||
name: 'Pizza',
|
||||
unit_price_with_taxes: 3,
|
||||
unit_price_without_taxes: 2,
|
||||
total_price_with_taxes: 18,
|
||||
total_price_without_taxes: 12,
|
||||
quantity: '10',
|
||||
discount: '40 %',
|
||||
}
|
||||
],
|
||||
};
|
||||
this.message('print_receipt',{receipt: receipt || sample_receipt});
|
||||
this.message('print_receipt',{receipt: receipt});
|
||||
},
|
||||
});
|
||||
|
||||
|
|
|
@ -325,7 +325,7 @@ function openerp_pos_models(instance, module){ //module is instance.point_of_sal
|
|||
push_order: function(record) {
|
||||
var self = this;
|
||||
return this.dao.add_operation(record).pipe(function(){
|
||||
return self.flush();
|
||||
return self.flush();
|
||||
});
|
||||
},
|
||||
|
||||
|
@ -616,9 +616,21 @@ function openerp_pos_models(instance, module){ //module is instance.point_of_sal
|
|||
export_as_JSON: function() {
|
||||
return {
|
||||
qty: this.get_quantity(),
|
||||
price_unit: this.get_product().get('list_price'),
|
||||
price_unit: this.get_list_price(),
|
||||
discount: this.get_discount(),
|
||||
product_id: this.get_product().get('id')
|
||||
product_id: this.get_product().get('id'),
|
||||
};
|
||||
},
|
||||
export_for_printing: function(){
|
||||
return {
|
||||
quantity: this.get_quantity(),
|
||||
unit_name: this.get_unit().name,
|
||||
list_price: this.get_list_price(),
|
||||
discount: this.get_discount(),
|
||||
product_name: this.get_product().get('name'),
|
||||
price_with_tax : this.get_price_with_tax(),
|
||||
price_without_tax: this.get_price_without_tax(),
|
||||
tax: this.get_tax(),
|
||||
};
|
||||
},
|
||||
get_price_without_tax: function(){
|
||||
|
@ -703,11 +715,17 @@ function openerp_pos_models(instance, module){ //module is instance.point_of_sal
|
|||
return {
|
||||
name: instance.web.datetime_to_str(new Date()),
|
||||
statement_id: this.get('id'),
|
||||
account_id: (this.get('account_id'))[0],
|
||||
journal_id: (this.get('journal_id'))[0],
|
||||
account_id: (this.cashregister.get('account_id'))[0],
|
||||
journal_id: (this.cashregister.get('journal_id'))[0],
|
||||
amount: this.get_amount()
|
||||
};
|
||||
},
|
||||
export_for_printing: function(){
|
||||
return {
|
||||
amount: this.get_amount(),
|
||||
journal: this.cashregister.get('journal_id')[1],
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
module.PaymentlineCollection = Backbone.Collection.extend({
|
||||
|
@ -796,6 +814,42 @@ function openerp_pos_models(instance, module){ //module is instance.point_of_sal
|
|||
getDueLeft: function() {
|
||||
return this.getTotal() - this.getPaidTotal();
|
||||
},
|
||||
export_for_printing: function(){
|
||||
var orderlines = [];
|
||||
this.get('orderLines').each(function(orderline){
|
||||
orderlines.push(orderline.export_for_printing());
|
||||
});
|
||||
|
||||
var paymentlines = [];
|
||||
this.get('paymentLines').each(function(paymentline){
|
||||
paymentlines.push(paymentline.export_for_printing());
|
||||
});
|
||||
var client = this.pos.get('client');
|
||||
var cashier = this.pos.get('cashier') || this.pos.get('user');
|
||||
var date = new Date();
|
||||
|
||||
return {
|
||||
orderlines: orderlines,
|
||||
paymentlines: paymentlines,
|
||||
total_with_tax: this.getTotal(),
|
||||
total_without_tax: this.getTotalTaxExcluded(),
|
||||
total_tax: this.getTax(),
|
||||
total_paid: this.getPaidTotal(),
|
||||
change: this.getChange(),
|
||||
name : this.getName(),
|
||||
client: client ? client.name : null ,
|
||||
cashier: cashier ? cashier.name : null,
|
||||
date: {
|
||||
year: date.getFullYear(),
|
||||
month: date.getMonth(),
|
||||
date: date.getDate(), // day of the month
|
||||
day: date.getDay(), // day of the week
|
||||
hour: date.getHours(),
|
||||
minute: date.getMinutes()
|
||||
},
|
||||
currency: this.pos.get('currency'),
|
||||
};
|
||||
},
|
||||
exportAsJSON: function() {
|
||||
var orderLines, paymentLines;
|
||||
orderLines = [];
|
||||
|
@ -835,7 +889,6 @@ function openerp_pos_models(instance, module){ //module is instance.point_of_sal
|
|||
this.selected_orderline = undefined;
|
||||
}
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
module.OrderCollection = Backbone.Collection.extend({
|
||||
|
|
|
@ -709,12 +709,15 @@ function openerp_pos_screens(instance, module){ //module is instance.point_of_sa
|
|||
var self = this;
|
||||
var currentOrder = this.pos.get('selectedOrder');
|
||||
|
||||
console.log('RECEIPT:',currentOrder.export_for_printing());
|
||||
|
||||
this.validate_button.$element.attr('disabled','disabled'); //FIXME is the css actually using this attr ?
|
||||
|
||||
this.pos.push_order(currentOrder.exportAsJSON())
|
||||
.then(function() {
|
||||
self.validate_button.$element.removeAttr('disabled');
|
||||
if(self.pos.use_proxy_printer){
|
||||
self.pos.proxy.print_receipt(currentOrder.export_for_printing());
|
||||
self.pos.get('selectedOrder').destroy(); //finish order and go back to scan screen
|
||||
}else{
|
||||
self.pos_widget.screen_selector.set_current_screen('receipt');
|
||||
|
@ -739,7 +742,6 @@ function openerp_pos_screens(instance, module){ //module is instance.point_of_sa
|
|||
this.renderElement();
|
||||
},
|
||||
addPaymentLine: function(newPaymentLine) {
|
||||
console.log('NEW PAYMENT LINE WIDGET',newPaymentLine);
|
||||
var x = new module.PaymentlineWidget(null, {
|
||||
payment_line: newPaymentLine
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue