Browse Source

proxy print + tare button.

pull/501/head
François Kawala 5 years ago
parent
commit
7d446a72dd
  1. 8
      pos_tare/static/src/css/pos_tare.css
  2. 55
      pos_tare/static/src/js/models.js
  3. 31
      pos_tare/static/src/js/screens.js
  4. 91
      pos_tare/static/src/xml/pos_tare.xml

8
pos_tare/static/src/css/pos_tare.css

@ -47,3 +47,11 @@
outline: none;
box-shadow: 0px 0px 0px 3px #6EC89B;
}
.pos .actionpad .button.pay {
height: 216px;
}
.pos .numpad button.input-button.numpad-backspace {
width: 216px;
}

55
pos_tare/static/src/js/models.js

@ -7,6 +7,32 @@ odoo.define('pos_tare.models', function (require) {
var _t = core._t;
class ValidationError extends Error {
constructor(message, gui) {
super(message); // (1)
this.name = "ValidationError"; // (2)
this.gui = gui;
}
}
var _NumpadState_ = models.NumpadState.prototype;
var NumpadState = models.NumpadState.extend({
appendNewChar: function(newChar) {
try {
_NumpadState_.appendNewChar.call(this, newChar);
} catch (error) {
if (error instanceof ValidationError) {
var title = _t("We can not apply this numpad action");
var popup = {title: title, body: error.message};
error.gui.show_popup('error', popup);
_NumpadState_.deleteLastChar.call(this);
}
}
},
});
var _super_ = models.Orderline.prototype;
var OrderLineWithTare = models.Orderline.extend({
@ -38,22 +64,23 @@ odoo.define('pos_tare.models', function (require) {
export_for_printing: function () {
var result = _super_.export_for_printing.call(this);
result.tare_quantity = this.get_tare();
result.gross_quantity = this.get_gross_weight();
return result;
},
// /////////////////////////////
// Custom Section
// /////////////////////////////
set_tare: function (quantity, update_net_weight) {
this.order.assert_editable();
// Prevent to apply multiple times a tare to the same product.
if (this.get_tare() > 0) {
throw new RangeError(_.str.sprintf(
_t("The tare (%s) is already set for the " +
"product \"%s\". We can not re-apply a tare to this " +
"product."),
this.get_tare_str_with_unit(), this.product.display_name));
// This is valid because the tare is stored using product UOM.
this.set_quantity(this.get_quantity() + this.get_tare());
this.reset_tare();
}
// We convert the tare that is always measured in the same UoM into
@ -68,11 +95,11 @@ odoo.define('pos_tare.models', function (require) {
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(
throw new ValidationError(_.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, line_unit.name,
this.get_quantity_str_with_unit()));
this.get_quantity_str_with_unit()), this.pos.gui);
}
// Update the quantity with the new weight net of tare quantity.
this.set_quantity(net_quantity);
@ -83,10 +110,18 @@ odoo.define('pos_tare.models', function (require) {
},
reset_tare: function () {
this.tare = 0;
},
get_tare: function () {
return this.tare;
},
get_gross_weight: function () {
return this.get_tare() + this.get_quantity();
},
get_tare_str_with_unit: function () {
var unit = this.get_unit();
var tare_str = pos_tare_tools.format_tare(
@ -101,7 +136,7 @@ odoo.define('pos_tare.models', function (require) {
var unit = this.get_unit();
var gross_weight_str = pos_tare_tools.format_tare(
this.pos,
this.get_tare() + this.get_quantity(),
this.get_gross_weight(),
this.get_unit(),
);
return gross_weight_str + ' ' + unit.name;
@ -109,6 +144,8 @@ odoo.define('pos_tare.models', function (require) {
});
models.Orderline = OrderLineWithTare;
models.NumpadState = NumpadState
models.Orderline = OrderLineWithTare;;
});

31
pos_tare/static/src/js/screens.js

@ -134,4 +134,35 @@ odoo.define('pos_tare.screens', function (require) {
});
screens.OrderWidget.include(
{
set_value: function(val) {
var order = this.pos.get_order();
if (order.get_selected_orderline()) {
var mode = this.numpad_state.get('mode');
if( mode === 'quantity'){
order.get_selected_orderline().set_quantity(val);
}else if( mode === 'discount'){
order.get_selected_orderline().set_discount(val);
}else if( mode === 'price'){
var selected_orderline = order.get_selected_orderline();
selected_orderline.price_manually_set = true;
selected_orderline.set_unit_price(val);
}else if( mode === 'tare'){
if (this.pos.config.iface_tare_method !== 'barcode') {
order.get_selected_orderline().set_tare(val, true);
} else {
this.gui.show_popup('error', {
'title': _t('Incorrect Tare Value'),
'body': _t('You can not set the tare' +
' manually. To be able to set the tare manually' +
' you have to change the tare input method' +
' in the POS configuration.'),
});
}
}
}
},});
});

91
pos_tare/static/src/xml/pos_tare.xml

@ -1,7 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates id="template" xml:space="preserve">
<t t-extend="ScaleScreenWidget">
<t t-jquery=".js-weight" t-operation="before">
<t t-if="widget.pos.config.iface_tare_method != 'barcode'">
@ -9,8 +8,7 @@
Gross Weight
</div>
<t t-if="widget.pos.config.iface_gross_weight_method == 'scale'">
<div class="weight-value weight-value-fixed"
id="container_weight_gross"/>
<div class="weight-value weight-value-fixed" id="container_weight_gross"/>
</t>
<t t-else="1">
<div class="weight-value weight-value-alterable">
@ -34,26 +32,97 @@
<t t-if="line.get_tare() !== 0">
<li class="info">
<i class="fa fa-beer"/>
Tare : <t t-esc="line.get_tare_str_with_unit()" />
Tare :
<t t-esc="line.get_tare_str_with_unit()"/>
</li>
</t>
</t>
</t>
<t t-name="PosTicket" t-extend="PosTicket">
<t t-jquery="tr[t-foreach='orderlines'] > td:nth-child(1)"
t-operation="append">
<t t-jquery="tr[t-foreach='orderlines'] > td:nth-child(1)" t-operation="append">
<t t-if="orderline.get_tare() > 0">
<div class="pos-disc-font">
Gross Weight : <t t-esc="orderline.get_gross_weight_str_with_unit()" /><br/>
Tare : <t t-esc="orderline.get_tare_str_with_unit()" /><br/>
Gross Weight :
<t t-esc="orderline.get_gross_weight_str_with_unit()"/><br/>
Tare :
<t t-esc="orderline.get_tare_str_with_unit()"/><br/>
</div>
</t>
</t>
</t>
<!-- TODO Overload XmlReceipt for Proxy usage -->
<!-- <t t-name="XmlReceipt" t-extend="XmlReceipt">
</t> -->
<t t-name="XmlReceipt" t-extend="XmlReceipt">
<t t-jquery=".orderlines" t-operation="inner">
<t t-foreach='receipt.orderlines' t-as='line'>
<t t-set='simple' t-value='line.discount === 0 and line.unit_name === "Unit(s)" and line.quantity === 1' />
<t t-if='simple'>
<line>
<left><t t-esc='line.product_name_wrapped[0]' /></left>
<right><value t-att-value-decimals='pos.currency.decimals'><t t-esc='line.price_display' /></value></right>
</line>
<t t-call="XmlReceiptWrappedProductNameLines"/>
</t>
<t t-if='!simple'>
<line><left><t t-esc='line.product_name_wrapped[0]' /></left></line>
<t t-call="XmlReceiptWrappedProductNameLines"/>
<t t-if='line.discount !== 0'>
<line indent='1'><left>Discount: <t t-esc='line.discount' />%</left></line>
</t>
<line indent='1'>
<left>
<value t-att-value-decimals='pos.dp["Product Unit of Measure"]' value-autoint='on'>
<t t-if="line.tare_quantity !== 0">
<t t-esc="line.gross_quantity" /> -
<t t-esc="line.tare_quantity"/> =
</t>
<t t-esc='line.quantity' />
</value>
<t t-if='line.unit_name !== "Unit(s)"'>
<t t-esc='line.unit_name' />
</t>
x
<value t-att-value-decimals='pos.dp["Product Price"]'>
<t t-esc='line.price' />
</value>
</left>
<right>
<value t-att-value-decimals='pos.currency.decimals'><t t-esc='line.price_display' /></value>
</right>
</line>
</t>
</t>
</t>
</t>
<t t-name="NumpadWidget">
<div class="numpad">
<button class="input-button number-char">1</button>
<button class="input-button number-char">2</button>
<button class="input-button number-char">3</button>
<button class="mode-button" data-mode='quantity'>Qty</button>
<br />
<button class="input-button number-char">4</button>
<button class="input-button number-char">5</button>
<button class="input-button number-char">6</button>
<button class="mode-button" data-mode='tare'>Tare</button>
<br />
<button class="input-button number-char">7</button>
<button class="input-button number-char">8</button>
<button class="input-button number-char">9</button>
<button class="mode-button" data-mode='discount'>Disc</button>
<br />
<button class="input-button numpad-minus" >+/-</button>
<button class="input-button number-char">0</button>
<button class="input-button number-char">.</button>
<button class="mode-button" data-mode='price'>Price</button>
<button class="input-button numpad-backspace">
<img style="pointer-events: none;" src="/point_of_sale/static/src/img/backspace.png" width="24" height="21" alt="Backspace"/>
</button>
</div>
</t>
</templates>
Loading…
Cancel
Save