[imp] modified code after Stéphane instructions
bzr revid: rlo@openerp.com-20120323143136-0qhzjnttnxei7xpi
This commit is contained in:
@@ -1260,7 +1260,7 @@ openerp.point_of_sale = function(db) {
|
||||
(this.shop.get('products')).reset(products);
|
||||
var self = this;
|
||||
// bind barcode reader event
|
||||
codeNumbers = []
|
||||
var codeNumbers = []
|
||||
$('body').delegate('','keyup', function (e){
|
||||
if (!isNaN(Number(String.fromCharCode(e.keyCode)))) {
|
||||
// a number
|
||||
@@ -1277,10 +1277,33 @@ openerp.point_of_sale = function(db) {
|
||||
codeNumbers.lastTimeStamp = new Date().getTime()
|
||||
if (codeNumbers.length == 13) {
|
||||
// a barcode reader
|
||||
console.log('barcode: ' + codeNumbers.join())
|
||||
selectedOrder = self.shop.get('selectedOrder')
|
||||
productsCollection = self.shop.get('products')
|
||||
scannedProductModel = _.detect(productsCollection.models, function(pc) { return pc.attributes.ean13 === codeNumbers.join('')})
|
||||
var barcode = codeNumbers.join('')
|
||||
console.log('barcode: ' + barcode)
|
||||
var selectedOrder = self.shop.get('selectedOrder')
|
||||
var productsCollection = self.shop.get('products')
|
||||
if (barcode.substring(0,2) in ['02', '22', '24', '26', '28']) {
|
||||
// product with a specific price - specified into the barcode
|
||||
barcode = barcode.substring(2,5)
|
||||
// TODO conversion euro - old local currencies
|
||||
price = Number(barcode.substring(7,5))/100
|
||||
weight = ''
|
||||
} else if (barcode.substring(0,2) in ['21','23','27','29','25']) {
|
||||
// product sold by weight
|
||||
barcode = barcode.substring(2,5)
|
||||
weight = Number(barcode.substring(7,5))/1000
|
||||
price = ''
|
||||
} else {
|
||||
// product unit
|
||||
weight = ''
|
||||
price = ''
|
||||
}
|
||||
var scannedProductModel = _.detect(productsCollection.models, function(pc) { return pc.attributes.ean13 === barcode})
|
||||
if (weight === '' and price !== '') {
|
||||
scannedProductModel.price = price
|
||||
} else if (weight !== '' and price === '') {
|
||||
// TODO sell by weight: how to calculate the price?
|
||||
scannedProductModel.price *= weight
|
||||
}
|
||||
selectedOrder.addProduct(scannedProductModel)
|
||||
|
||||
codeNumbers = []
|
||||
|
||||
Reference in New Issue
Block a user