diff --git a/pos_tare/__manifest__.py b/pos_tare/__manifest__.py
index da757731..7c7ca29d 100644
--- a/pos_tare/__manifest__.py
+++ b/pos_tare/__manifest__.py
@@ -10,7 +10,6 @@
"license": "AGPL-3",
"maintainers": ["fkawala"],
"depends": ["point_of_sale"],
- "demo": ["demo/uom_uom.xml"],
"data": [
"views/templates.xml",
"views/view_pos_config.xml",
diff --git a/pos_tare/demo/uom_uom.xml b/pos_tare/demo/uom_uom.xml
deleted file mode 100644
index da5fe482..00000000
--- a/pos_tare/demo/uom_uom.xml
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
-
-
- Kg
-
-
- bigger
-
-
diff --git a/pos_tare/models/pos_config.py b/pos_tare/models/pos_config.py
index a73eee51..01595485 100644
--- a/pos_tare/models/pos_config.py
+++ b/pos_tare/models/pos_config.py
@@ -1,4 +1,4 @@
-from odoo import models, fields
+from odoo import api, models, fields
class PosConfig(models.Model):
@@ -11,8 +11,20 @@ class PosConfig(models.Model):
],
string='Tare input method',
default='both',
+ required=True,
help="Select tare method:\n"
"* 'manual' : the scale screen has an extra tare input field;\n"
"* 'barecode' : (scan a barcode to tare the selected order line;\n"
"* 'both' : manual input and barcode methods are enabled;",
)
+
+ iface_tare_uom_id = fields.Many2one(
+ string="Unit of Measure of the tare",
+ comodel_name="uom.uom",
+ default=lambda s: s._default_iface_tare_uom_id(),
+ required=True,
+ )
+
+ @api.model
+ def _default_iface_tare_uom_id(self):
+ return self.env.ref("uom.product_uom_kgm")
diff --git a/pos_tare/static/src/js/models.js b/pos_tare/static/src/js/models.js
index f594ccd9..36eacebd 100644
--- a/pos_tare/static/src/js/models.js
+++ b/pos_tare/static/src/js/models.js
@@ -60,21 +60,21 @@ odoo.define('pos_tare.models', function (require) {
this.get_tare_str_with_unit(), this.product.display_name));
}
- // We convert the tare that is always measured in kilogrammes into
+ // We convert the tare that is always measured in the same UoM into
// the unit of measure for this order line.
- var kg = pos_tare_tools.get_unit(this.pos, "kg");
+ var tare_unit = this.pos.units_by_id[this.pos.config.iface_tare_uom_id[0]];
var tare = parseFloat(quantity) || 0;
- var unit = this.get_unit();
- var tare_in_product_uom = pos_tare_tools.convert_mass(tare, kg, unit);
+ var line_unit = this.get_unit();
+ var tare_in_product_uom = pos_tare_tools.convert_mass(tare, tare_unit, line_unit);
var tare_in_product_uom_string = pos_tare_tools.format_tare(this.pos,
- tare_in_product_uom, unit);
+ tare_in_product_uom, line_unit);
var net_quantity = this.get_quantity() - tare_in_product_uom;
// This method fails when the net weight is negative.
if (net_quantity <= 0) {
throw new RangeError(_.str.sprintf(
_t("The tare weight is %s %s, it's greater or equal to " +
"the product weight %s. We can not apply this tare."),
- tare_in_product_uom_string, unit.name,
+ tare_in_product_uom_string, line_unit.name,
this.get_quantity_str_with_unit()));
}
// Update tare value.
diff --git a/pos_tare/static/src/js/tools.js b/pos_tare/static/src/js/tools.js
index fd597952..e1c349d9 100644
--- a/pos_tare/static/src/js/tools.js
+++ b/pos_tare/static/src/js/tools.js
@@ -9,15 +9,6 @@ odoo.define('pos_tare.tools', function (require) {
var round_pr = utils.round_precision;
var round_di = utils.round_decimals;
- // Define functions used to do unit operation.
- // Get unit search for unit based on unit name.
- var get_unit = function (pos, unit_name) {
- return pos.units.filter(
- function (u) {
- return u.name === unit_name;
- })[0];
- };
-
// Convert mass using the reference UOM as pivot unit.
var convert_mass = function (mass, from_unit, to_unit) {
// There is no conversion from one category to another.
@@ -65,7 +56,6 @@ odoo.define('pos_tare.tools', function (require) {
};
return {
- get_unit: get_unit,
convert_mass: convert_mass,
format_tare: format_tare,
};
diff --git a/pos_tare/views/view_pos_config.xml b/pos_tare/views/view_pos_config.xml
index faf2f116..8e6e667a 100644
--- a/pos_tare/views/view_pos_config.xml
+++ b/pos_tare/views/view_pos_config.xml
@@ -22,6 +22,19 @@
+