Browse Source

[ADD] tare field on pos.order.line model

pull/501/head
Sylvain LE GAL 4 years ago
parent
commit
8765185e95
  1. 3
      pos_tare/__manifest__.py
  2. 1
      pos_tare/models/__init__.py
  3. 15
      pos_tare/models/pos_order_line.py
  4. 26
      pos_tare/static/src/js/models.js
  5. 0
      pos_tare/views/view_pos_config.xml
  6. 16
      pos_tare/views/view_pos_order.xml

3
pos_tare/__manifest__.py

@ -13,7 +13,8 @@
"demo": ["demo/uom_uom.xml"],
"data": [
"views/templates.xml",
"views/pos_config_view.xml",
"views/view_pos_config.xml",
"views/view_pos_order.xml",
"data/barcode_rule.xml",
],
"qweb": [

1
pos_tare/models/__init__.py

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

15
pos_tare/models/pos_order_line.py

@ -0,0 +1,15 @@
# Copyright (C) 2020-Today: GRAP (<http://www.grap.coop/>)
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import models, fields
from odoo.addons import decimal_precision as dp
class PosOrderLine(models.Model):
_inherit = "pos.order.line"
tare = fields.Float(
string="Tare",
digits=dp.get_precision("Product Unit of Measure")
)

26
pos_tare/static/src/js/models.js

@ -14,28 +14,28 @@ odoo.define('pos_tare.models', function (require) {
// Overload Section
// /////////////////////////////
initialize: function (session, attributes) {
this.tareQuantity = 0;
this.tareQuantityStr = '0';
this.tare = 0;
this.tareStr = '0';
return _super_.initialize.call(this, session, attributes);
},
init_from_JSON: function (json) {
_super_.init_from_JSON.call(this, json);
this.tareQuantity = json.tareQuantity ||0;
this.tareQuantityStr = json.tareQuantityStr ||'0';
this.tare = json.tare ||0;
this.tareStr = json.tareStr ||'0';
},
clone: function () {
var orderline = _super_.clone.call(this);
orderline.tareQuantity = this.tareQuantity;
orderline.tareQuantityStr = this.tareQuantityStr;
orderline.tare = this.tare;
orderline.tareStr = this.tareStr;
return orderline;
},
export_as_JSON: function () {
var json = _super_.export_as_JSON.call(this);
json.tareQuantity = this.get_tare();
json.tareQuantityStr = this.get_tare_str();
json.tare = this.get_tare();
json.tareStr = this.get_tare_str();
return json;
},
@ -78,24 +78,24 @@ odoo.define('pos_tare.models', function (require) {
this.get_quantity_str_with_unit()));
}
// Update tare value.
this.tareQuantity = tare_in_product_uom;
this.tareQuantityStr = tare_in_product_uom_string;
this.tare = tare_in_product_uom;
this.tareStr = tare_in_product_uom_string;
// Update the quantity with the new weight net of tare quantity.
this.set_quantity(net_quantity);
this.trigger('change', this);
},
get_tare: function () {
return this.tareQuantity;
return this.tare;
},
get_tare_str: function () {
return this.tareQuantityStr;
return this.tareStr;
},
get_tare_str_with_unit: function () {
var unit = this.get_unit();
return this.tareQuantityStr + ' ' + unit.name;
return this.tareStr + ' ' + unit.name;
},
});

0
pos_tare/views/pos_config_view.xml → pos_tare/views/view_pos_config.xml

16
pos_tare/views/view_pos_order.xml

@ -0,0 +1,16 @@
<?xml version="1.0"?>
<odoo>
<record model="ir.ui.view" id="view_pos_order_form">
<field name="model">pos.order</field>
<field name="inherit_id" ref="point_of_sale.view_pos_pos_form"/>
<field name="arch" type="xml">
<field name="qty" position="after">
<field name="tare"/>
</field>
</field>
</record>
</odoo>
Loading…
Cancel
Save