Browse Source

[IMP] make dynamic the UoM used for the tare. (setting in pos.config)

pull/501/head
Sylvain LE GAL 4 years ago
parent
commit
9be069878f
  1. 1
      pos_tare/__manifest__.py
  2. 10
      pos_tare/demo/uom_uom.xml
  3. 14
      pos_tare/models/pos_config.py
  4. 12
      pos_tare/static/src/js/models.js
  5. 10
      pos_tare/static/src/js/tools.js
  6. 13
      pos_tare/views/view_pos_config.xml

1
pos_tare/__manifest__.py

@ -10,7 +10,6 @@
"license": "AGPL-3", "license": "AGPL-3",
"maintainers": ["fkawala"], "maintainers": ["fkawala"],
"depends": ["point_of_sale"], "depends": ["point_of_sale"],
"demo": ["demo/uom_uom.xml"],
"data": [ "data": [
"views/templates.xml", "views/templates.xml",
"views/view_pos_config.xml", "views/view_pos_config.xml",

10
pos_tare/demo/uom_uom.xml

@ -1,10 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="product_uom_kgm_dbg" model="uom.uom">
<field name="category_id" ref="uom.product_uom_categ_kgm"/>
<field name="name">Kg</field>
<field name="factor" eval="1"/>
<field name="rounding" eval="0.001"/>
<field name="uom_type">bigger</field>
</record>
</odoo>

14
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): class PosConfig(models.Model):
@ -11,8 +11,20 @@ class PosConfig(models.Model):
], ],
string='Tare input method', string='Tare input method',
default='both', default='both',
required=True,
help="Select tare method:\n" help="Select tare method:\n"
"* 'manual' : the scale screen has an extra tare input field;\n" "* 'manual' : the scale screen has an extra tare input field;\n"
"* 'barecode' : (scan a barcode to tare the selected order line;\n" "* 'barecode' : (scan a barcode to tare the selected order line;\n"
"* 'both' : manual input and barcode methods are enabled;", "* '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")

12
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)); 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. // 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 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, 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; var net_quantity = this.get_quantity() - tare_in_product_uom;
// This method fails when the net weight is negative. // This method fails when the net weight is negative.
if (net_quantity <= 0) { if (net_quantity <= 0) {
throw new RangeError(_.str.sprintf( throw new RangeError(_.str.sprintf(
_t("The tare weight is %s %s, it's greater or equal to " + _t("The tare weight is %s %s, it's greater or equal to " +
"the product weight %s. We can not apply this tare."), "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())); this.get_quantity_str_with_unit()));
} }
// Update tare value. // Update tare value.

10
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_pr = utils.round_precision;
var round_di = utils.round_decimals; 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. // Convert mass using the reference UOM as pivot unit.
var convert_mass = function (mass, from_unit, to_unit) { var convert_mass = function (mass, from_unit, to_unit) {
// There is no conversion from one category to another. // There is no conversion from one category to another.
@ -65,7 +56,6 @@ odoo.define('pos_tare.tools', function (require) {
}; };
return { return {
get_unit: get_unit,
convert_mass: convert_mass, convert_mass: convert_mass,
format_tare: format_tare, format_tare: format_tare,
}; };

13
pos_tare/views/view_pos_config.xml

@ -22,6 +22,19 @@
</div> </div>
</div> </div>
</div> </div>
<div class="col-xs-12 col-lg-6 o_setting_box" id="iface_tare_method">
<div class="o_setting_right_pane">
<label for="iface_tare_uom_id" string="Tare UoM"/>
<div class="text-muted">
Unit of Measure of the tares.
</div>
<div class="content-group">
<div class="mt16">
<field name="iface_tare_uom_id" class="o_light_label"/>
</div>
</div>
</div>
</div>
</xpath> </xpath>
</field> </field>
</record> </record>

Loading…
Cancel
Save