Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion pos_barcode_tare/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
# -*- coding: utf-8 -*-
from . import models
108 changes: 60 additions & 48 deletions pos_barcode_tare/static/src/css/pos_barcode_tare.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,39 @@
color: inherit;
}

.pos .pos-tare-label {
width: 300px;
background-color: white;
margin: 20px;
padding: 15px;
font-size: 21px;
padding-bottom:30px;
display: inline-block;
font-family: "Inconsolata";
border: solid 1px rgb(220,220,220);
border-radius: 3px;
overflow: hidden;
.pos .tare-screen .centered-content {
text-align:center;
}

.pos .pos-tare-label .caption {
@media screen {
.pos .tare-screen .pos-tare-label-container {
width: 300px;
background-color: white;
margin: 20px;
padding: 15px;
font-size: 21px;
padding-bottom:30px;
font-family: "Inconsolata";
border: solid 1px rgb(220,220,220);
border-radius: 3px;
overflow: hidden;
text-align: center;
display: inline-block;
justify-content: center;
align-items: center;
flex-wrap: wrap;
}

.pos .tare-screen .pos-tare-label-container img {
width: 50mm;
height: 45mm;
}
}

.pos .tare-screen .pos-tare-label-container .caption {
display: block;
text-overflow: ellipsis;
flex-basis: 100vw;
}

.pos .tare-screen .pos-directions-for-user {
Expand All @@ -48,12 +65,7 @@
margin-right: auto;
}

.pos .pos-tare-label img {
width: 50mm;
height: 45mm;
}

.pos .tare-screen .print-label {
.pos .tare-screen .centered-content .print-label {
text-align: center;
font-size: 32px;
background: rgb(110,200,155);
Expand All @@ -65,47 +77,47 @@
}

@media print {
body {
position: relative !important;
}

.pos .tare-screen header,
.pos .tare-screen .top-content,
.pos .tare-screen .centered-content .print-label,
.pos .tare-screen .print-label,
.pos .tare-screen .pos-directions-for-user {
display: none !important;
}

.pos .tare-screen .screen-content {
max-width: unset !important;
}

.pos .tare-screen .centered-content {
position: static;
text-align: center;
border: none;
width: 100vw;
height: 100vh;
margin: 0mm;
page-break-inside: avoid;
overflow: hidden;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
flex-wrap: wrap;
left: unset !important;
right: unset !important;
}

.pos .pos-tare-label .caption {
display: block;
}

.pos .pos-tare-paper {
margin: 0;
margin-left: 0 !important;
margin-right: 0 !important;
width: 99% !important;
height: 99% !important;
display: block;
position: fixed;
display: flex !important;
justify-content: center !important;
align-items: center !important;
}

.pos-tare-label img {
width: 27mm !important;
height: 21mm !important;
display: run-in;
.pos .tare-screen .centered-content .pos-tare-label-container img {
width: 90vw;
height: 70vh;
}

.pos .pos-tare-label {
margin: 0;
margin-left: 0 !important;
margin-right: 0 !important;
position: fixed !important;
border: none !important;
font-size: 10px !important;
.pos .tare-screen .centered-content .pos-tare-label-container .caption {
text-overflow: ellipsis;
font-size: 5vh;
flex-basis: 100%;
}
}
49 changes: 28 additions & 21 deletions pos_barcode_tare/static/src/js/pos_barcode_tare.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
odoo.define('pos_barcode_tare.screens', function (require) {

"use strict";
var chrome = require('point_of_sale.chrome');
var core = require('web.core');
var devices = require('point_of_sale.devices');
var gui = require('point_of_sale.gui');
var models = require('point_of_sale.models');
var screens = require('point_of_sale.screens');
Expand Down Expand Up @@ -59,6 +57,18 @@ odoo.define('pos_barcode_tare.screens', function (require) {
return result || 0;
};

// Format the tare value.
var format_tare = function (pos, qty, unit) {
if (unit.rounding) {
var q = round_pr(qty, unit.rounding);
var decimals = pos.dp['Product Unit of Measure'];
return formats.format_value(
round_di(q, decimals),
{type: 'float', digits: [69, decimals]});
}
return qty.toFixed(0);
};

// This configures read action for tare barcode. A tare barcode contains a
// fake product ID and the weight to be subtracted from the product in the
// latest order line.
Expand All @@ -67,9 +77,9 @@ odoo.define('pos_barcode_tare.screens', function (require) {
barcode_tare_action: function (code) {
try {
var order = this.pos.get_order();
var last_order_line = order.get_last_orderline();
var selected_order_line = order.get_selected_orderline();
var tare_weight = code.value;
last_order_line.set_tare(tare_weight);
selected_order_line.set_tare(tare_weight);
} catch (error) {
var title = _t("We can not apply this tare barcode.");
var popup = {title: title, body: error.message};
Expand Down Expand Up @@ -223,6 +233,7 @@ odoo.define('pos_barcode_tare.screens', function (require) {
},
print_web: function () {
window.print();
// TODO check this
this.pos.get_order()._printed = true;
},
print: function () {
Expand Down Expand Up @@ -261,14 +272,17 @@ odoo.define('pos_barcode_tare.screens', function (require) {
delete this.weight;
this.pos.proxy_queue.clear();
},
get_tare_str: function () {
return format_tare(this.pos, this.get_weight(),
get_unit(this.pos, "kg"));
},
});

gui.define_screen({name:'tare', widget: TareScreenWidget});

// Update Orderline model
var _super_ = models.Orderline.prototype;

models.Orderline = models.Orderline.extend({
var OrderLineWithTare = models.Orderline.extend({
initialize: function (session, attributes) {
this.tareQuantity = 0;
this.tareQuantityStr = '0';
Expand All @@ -291,27 +305,14 @@ odoo.define('pos_barcode_tare.screens', function (require) {
this.get_tare_str_with_unit(), this.product.display_name));
}

var self = this;
// This function is used to format the quantity into string
// according to the rounding specifications.
var stringify = function (qty) {
var unit = self.get_unit();
if (unit.rounding) {
var q = round_pr(qty, unit.rounding);
var decimals = self.pos.dp['Product Unit of Measure'];
return formats.format_value(
round_di(q, decimals),
{type: 'float', digits: [69, decimals]});
}
return qty.toFixed(0);
};
// We convert the tare that is always measured in kilogrammes into
// the unit of measure for this order line.
var kg = get_unit(this.pos, "kg");
var tare = parseFloat(quantity) || 0;
var unit = this.get_unit();
var tare_in_product_uom = convert_mass(tare, kg, unit);
var tare_in_product_uom_string = stringify(tare_in_product_uom);
var tare_in_product_uom_string = format_tare(this.pos,
tare_in_product_uom, unit);
var net_quantity = this.get_quantity() - tare_in_product_uom;
// This method fails when the net weight is negative.
if (net_quantity <= 0) {
Expand Down Expand Up @@ -356,4 +357,10 @@ odoo.define('pos_barcode_tare.screens', function (require) {
return result;
},
});

models.Orderline = OrderLineWithTare;

return {TareScreenWidget: TareScreenWidget,
OrderLineWithTare: OrderLineWithTare,
get_unit: get_unit};
});
12 changes: 4 additions & 8 deletions pos_barcode_tare/static/src/xml/pos_barcode_tare.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,10 @@
</t>

<t t-name="PosTareLabel">
<div class="pos-center-align">
<div class="pos-tare-paper">
<div class="pos-tare-label">
<img t-att-src="'/report/barcode/EAN13/' + widget.get_barcode_data()" />
<span class="caption">tare = <t t-esc="widget.get_weight()" />kg</span>
</div>
</div>
</div>
<img t-att-src="'/report/barcode/EAN13/' + widget.get_barcode_data()" />
<span class="caption">
tare = <t t-esc="widget.get_tare_str()" /> kg
</span>
</t>

<t t-name="TareScreenButton">
Expand Down
Loading