Browse Source

Define a "tare" barcode type instead of hijacking the weight type.

pull/501/head
François Kawala 5 years ago
parent
commit
b2799ef6cb
  1. 1
      pos_barcode_tare/models/__init__.py
  2. 14
      pos_barcode_tare/models/barcode_rule.py
  3. 9
      pos_barcode_tare/models/pos_config.py
  4. 2
      pos_barcode_tare/readme/USAGE.rst
  5. 24
      pos_barcode_tare/static/src/js/pos_barcode_tare.js
  6. 12
      pos_barcode_tare/views/pos_config_view.xml

1
pos_barcode_tare/models/__init__.py

@ -1 +1,2 @@
from . import pos_config
from . import barcode_rule

14
pos_barcode_tare/models/barcode_rule.py

@ -0,0 +1,14 @@
# -*- coding: utf-8 -*-
from openerp import _, models, fields, api
class BarcodeRule(models.Model):
_inherit = 'barcode.rule'
@api.model
def _get_type_selection(self):
res = super(BarcodeRule, self)._get_type_selection()
res.append(
('tare', _('Tare')))
return res

9
pos_barcode_tare/models/pos_config.py

@ -9,12 +9,3 @@ class PosConfig(models.Model):
'Show tare label button',
help="Print tare labels with this POS"
)
iface_tare_barcode_sequence_id = fields.Integer(
'Barcode nomenclature sequence ID',
default=36,
required=True,
help="""The nomenclature ID gives barcode pattern.
It can be found in POS Barcode Nomenclatures. The expected barcode
pattern is 21.....{NNDDD}"""
)

2
pos_barcode_tare/readme/USAGE.rst

@ -1,4 +1,4 @@
Install this add-on and configure the point of sale where you want to be able to use the tare barecode. Setup the default barcode sequence ID according to your barcode nomenclature. The barcode pattern should be ``XX.....NNDDD`` where XX is the barcode prefix. In the default barcode nomenclature, the weight barcode pattern sequence id is 36 and its prefix is 21. The label printing is done using web print. To streamline the label printing it is advised to use the silent printing mode (firefox) or the kiosk printing (chrome).
Install this add-on and configure the point of sale where you want to be able to use the tare barecode. The label printing is done using web print. To streamline the label printing it is advised to use the silent printing mode (firefox) or the kiosk printing (chrome).
The command line to start a chrome base browser in kiosk mode with silent printing looks like:

24
pos_barcode_tare/static/src/js/pos_barcode_tare.js

@ -12,6 +12,7 @@ odoo.define('pos_barcode_tare.screens', function (require) {
var QWeb = core.qweb;
var _t = core._t;
var round_pr = utils.round_precision;
var tare_barcode_type = "tare";
// Define functions used to do unit operation.
// Get unit search for unit based on unit name.
@ -54,7 +55,7 @@ odoo.define('pos_barcode_tare.screens', function (require) {
// latest order line.
screens.ScreenWidget.include(
{
barcode_weight_action: function (code) {
barcode_tare_action: function (code) {
var order = this.pos.get_order();
// Computes the paid weight
var last_order_line = order.get_last_orderline();
@ -95,8 +96,8 @@ odoo.define('pos_barcode_tare.screens', function (require) {
show: function () {
this._super();
this.pos.barcode_reader.set_action_callback(
'weight',
_.bind(this.barcode_weight_action, this));
'tare',
_.bind(this.barcode_tare_action, this));
},
});
@ -132,8 +133,7 @@ odoo.define('pos_barcode_tare.screens', function (require) {
// Fetch the unit of measure used to save the tare
this.kg_unit = get_unit(this.pos, "kg");
// Fetch the barcode prefix from POS barcode parser rules.
this.weight_barcode_prefix = this.get_barcode_prefix(
this.pos.config.iface_tare_barcode_sequence_id);
this.weight_barcode_prefix = this.get_barcode_prefix();
// Setup the proxy
var queue = this.pos.proxy_queue;
// The pooling of the scale starts here.
@ -148,15 +148,17 @@ odoo.define('pos_barcode_tare.screens', function (require) {
this.render_receipt();
this.lock_screen(true);
},
get_barcode_prefix: function (barcode_sequence_id) {
var barcode_pattern = this.get_barcode_pattern(barcode_sequence_id);
get_barcode_prefix: function () {
var barcode_pattern = this.get_barcode_pattern();
return barcode_pattern.substr(0, 2);
},
get_barcode_pattern: function (barcode_sequence_id) {
get_barcode_pattern: function () {
var rules = this.get_barcode_rules();
var rule = rules.filter(
function (r) {
return r.sequence === barcode_sequence_id;
// We select the first (smallest sequence ID) barcode rule
// with the expected type.
return r.type === tare_barcode_type;
})[0];
return rule.pattern;
},
@ -191,8 +193,8 @@ odoo.define('pos_barcode_tare.screens', function (require) {
return checksum % 10;
},
barcode_data: function (weight) {
// We use EAN13 barcode, it looks like 21 00000 12345 x. First there
// is the prefix, here 21, that is used to decide which type of
// 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
// barcode we're dealing with. A weight barcode has then two groups
// of five digits. The first group encodes the product id. Here the
// product id is 00000. The second group encodes the weight in

12
pos_barcode_tare/views/pos_config_view.xml

@ -1,6 +1,6 @@
<?xml version="1.0"?>
<odoo>
<odoo noupdate="1">
<record model="ir.ui.view" id="view_pos_config_form">
<field name="model">pos.config</field>
<field name="inherit_id" ref="point_of_sale.view_pos_config_form" />
@ -9,9 +9,17 @@
<separator string="Loose good options" colspan="4"/>
<group>
<field name="iface_tare_label" />
<field name="iface_tare_barcode_sequence_id" />
</group>
</xpath>
</field>
</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>
Loading…
Cancel
Save