Browse Source

Fix XML, refacto, better alert message.

pull/501/head
Francois Kawala 5 years ago
committed by François Kawala
parent
commit
7bf9eb478d
  1. 3
      pos_barcode_tare/__openerp__.py
  2. 12
      pos_barcode_tare/data/barcode_rule.xml
  3. 0
      pos_barcode_tare/pos_barcode_tare.xml
  4. 28
      pos_barcode_tare/static/src/js/pos_barcode_tare.js
  5. 11
      pos_barcode_tare/views/pos_config_view.xml

3
pos_barcode_tare/__openerp__.py

@ -12,8 +12,9 @@
'license': 'AGPL-3', 'license': 'AGPL-3',
'depends': ['point_of_sale'], 'depends': ['point_of_sale'],
'data': [ 'data': [
'pos_barcode_tare.xml',
'views/pos_config_view.xml', 'views/pos_config_view.xml',
'views/pos_barcode_tare.xml',
'data/barcode_rule.xml',
], ],
'qweb': [ 'qweb': [
'static/src/xml/pos_barcode_tare.xml', 'static/src/xml/pos_barcode_tare.xml',

12
pos_barcode_tare/data/barcode_rule.xml

@ -0,0 +1,12 @@
<?xml version="1.0"?>
<odoo noupdate="1">
<record id="barcode_rule_tare" model="barcode.rule">
<field name="name">Tare</field>
<field name="barcode_nomenclature_id" ref="barcodes.default_barcode_nomenclature"/>
<field name="sequence">81</field>
<field name="type">tare</field>
<field name="encoding">ean13</field>
<field name="pattern">0700000{NNDDD}</field>
</record>
</odoo>

0
pos_barcode_tare/views/pos_barcode_tare.xml → pos_barcode_tare/pos_barcode_tare.xml

28
pos_barcode_tare/static/src/js/pos_barcode_tare.js

@ -180,18 +180,6 @@ odoo.define('pos_barcode_tare.screens', function (require) {
} }
return this.weight_in_kg; return this.weight_in_kg;
}, },
ean13_checksum: function (s) {
var result = 0;
for (var counter = s.length-1; counter >=0; counter--) {
var counterCheckSum = counter % 2;
counterCheckSum *= 2;
counterCheckSum += 1;
result += parseInt(s.charAt(counter), 10) * counterCheckSum;
}
var checksum = 10;
checksum -= result % 10;
return checksum % 10;
},
barcode_data: function (weight) { barcode_data: function (weight) {
// We use EAN13 barcode, it looks like 07 00000 12345 x. First there // We use EAN13 barcode, it looks like 07 00000 12345 x. First there
// is the prefix, here 07, that is used to decide which type of // is the prefix, here 07, that is used to decide which type of
@ -207,13 +195,15 @@ odoo.define('pos_barcode_tare.screens', function (require) {
var weight_with_padding = '0'.repeat(padding_size) + weight_in_gram; var weight_with_padding = '0'.repeat(padding_size) + weight_in_gram;
var padded_weight = weight_with_padding.substr( var padded_weight = weight_with_padding.substr(
weight_with_padding.length - padding_size); weight_with_padding.length - padding_size);
// Builds the barcode data (ie. all but the checksum).
var barcode_data = this.weight_barcode_prefix
.concat(void_product_id, padded_weight);
// Compute checksum and concat with barcode data to get the actual
// barcode.
var checksum = this.ean13_checksum(barcode_data);
return barcode_data.concat(checksum);
// Builds the barcode using a placeholder checksum.
var barcode = this.weight_barcode_prefix
.concat(void_product_id, padded_weight)
.concat(0);
// Compute checksum
var barcode_parser = this.pos.barcode_reader.barcode_parser;
var checksum = barcode_parser.ean_checksum(barcode);
// Replace checksum placeholder by the actual checksum.
return barcode.substr(0, 12).concat(checksum);
}, },
get_barcode_data: function () { get_barcode_data: function () {
return this.barcode_data(this.get_weight()); return this.barcode_data(this.get_weight());

11
pos_barcode_tare/views/pos_config_view.xml

@ -1,6 +1,6 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<odoo noupdate="1">
<odoo>
<record model="ir.ui.view" id="view_pos_config_form"> <record model="ir.ui.view" id="view_pos_config_form">
<field name="model">pos.config</field> <field name="model">pos.config</field>
<field name="inherit_id" ref="point_of_sale.view_pos_config_form" /> <field name="inherit_id" ref="point_of_sale.view_pos_config_form" />
@ -13,13 +13,4 @@
</xpath> </xpath>
</field> </field>
</record> </record>
<record id="barcode_rule_tare" model="barcode.rule">
<field name="name">Tare</field>
<field name="barcode_nomenclature_id" ref="barcodes.default_barcode_nomenclature"/>
<field name="sequence">81</field>
<field name="type">tare</field>
<field name="encoding">ean13</field>
<field name="pattern">0700000{NNDDD}</field>
</record>
</odoo> </odoo>
Loading…
Cancel
Save