Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[14.0][MIG] pos_tare: Migration to 14.0 #980

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
da44d2c
[ADD][8.0] pos_tare
legalsylvain Jan 8, 2020
354cca3
[REF] pos_tare: Black python code
legalsylvain Jan 8, 2020
db2d783
[MIG] pos_tare: Migration to 12.0
legalsylvain Jan 8, 2020
34df026
[UPD] Update pos_tare.pot
oca-travis Jul 23, 2020
dc4f41e
[UPD] README.rst
OCA-git-bot Jul 23, 2020
4690306
pos_tare 12.0.1.0.1
OCA-git-bot Jul 23, 2020
09ba906
Added translation using Weblate (Spanish)
danimv5 Jul 27, 2020
fc3db49
Translated using Weblate (Spanish)
danimv5 Jul 27, 2020
0ac84d9
[UPD] Update pos_tare.pot
oca-travis Oct 30, 2020
6508d9c
Update translation files
oca-transbot Oct 30, 2020
c6a8b79
[FIX] pos_tare : raise an error if the gross weight is not correct
legalsylvain Nov 16, 2020
1aa252c
[FIX] pos_tare : move the confirm popup regarding null or negative qu…
legalsylvain Nov 20, 2020
ada6c5e
[UPD] Update pos_tare.pot
oca-travis Dec 15, 2020
e36c487
pos_tare 12.0.1.0.2
OCA-git-bot Dec 15, 2020
cc340a9
Update translation files
oca-transbot Dec 15, 2020
61a3434
[UPD] Update pos_tare.pot
oca-travis Dec 15, 2020
3ab0fd8
Update translation files
oca-transbot Dec 15, 2020
64d85d0
[IMP][12.O] pos_tare : add default tare weight on product.template model
legalsylvain May 24, 2021
a7d165a
[UPD] Update pos_tare.pot
oca-travis Jun 12, 2021
ad8d038
[UPD] README.rst
OCA-git-bot Jun 12, 2021
17558c8
pos_tare 12.0.1.0.3
OCA-git-bot Jun 12, 2021
915d77e
Update translation files
oca-transbot Jun 12, 2021
3c52604
[UPD] Update pos_tare.pot
oca-travis Jun 12, 2021
68a40e2
Update translation files
oca-transbot Jun 12, 2021
5a0a231
Added translation using Weblate (Italian)
mymage Mar 17, 2023
c393ff7
Translated using Weblate (Italian)
mymage Mar 17, 2023
096f471
[IMP] pos_tare: black, isort, prettier
baimont Apr 7, 2023
325ae22
[MIG] pos_tare: Migration to 14.0
baimont Apr 7, 2023
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
7 changes: 5 additions & 2 deletions pos_tare/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{
"name": "Point Of Sale - Tare",
"summary": "Manage Tare in Point Of Sale module",
"version": "12.0.1.0.3",
"version": "14.0.1.0.0",
"category": "Point of Sale",
"author": "GRAP, Le Nid, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/pos",
Expand All @@ -20,7 +20,10 @@
"data/barcode_rule.xml",
],
"qweb": [
"static/src/xml/pos_tare.xml",
"static/src/xml/Screens/ProductScreen/Orderline.xml",
"static/src/xml/Screens/ProductScreen/NumpadWidget.xml",
"static/src/xml/Screens/ReceiptScreen/OrderReceipt.xml",
"static/src/xml/Screens/ScaleScreen/ScaleScreen.xml",
],
"demo": [
"demo/product_product.xml",
Expand Down
4 changes: 3 additions & 1 deletion pos_tare/models/barcode_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@
class BarcodeRule(models.Model):
_inherit = "barcode.rule"

type = fields.Selection(selection_add=[("tare", "Tare")])
type = fields.Selection(
selection_add=[("tare", "Tare")], ondelete={"tare": "set default"}
)
5 changes: 2 additions & 3 deletions pos_tare/models/pos_order_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@

from odoo import fields, models

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")
string="Tare",
digits="Product Unit of Measure",
)
4 changes: 1 addition & 3 deletions pos_tare/models/product_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@

from odoo import fields, models

import odoo.addons.decimal_precision as dp


class ProductTemplate(models.Model):
_inherit = "product.template"

tare_weight = fields.Float(
digits=dp.get_precision("Product Unit of Measure"),
digits="Product Unit of Measure",
string="Tare Weight",
help="Set here Constant tare weight"
" for the given product. This tare will be substracted when"
Expand Down
167 changes: 167 additions & 0 deletions pos_tare/static/src/js/Screens/ProductScreen/ProductScreen.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
odoo.define("pos_tare.screens", function (require) {
"use strict";
const ProductScreen = require("point_of_sale.ProductScreen");
const Registries = require("point_of_sale.Registries");
const {useBarcodeReader} = require("point_of_sale.custom_hooks");

const TareProductScreen = (ProductScreen) =>
class extends ProductScreen {
constructor() {
super(...arguments);
useBarcodeReader({
// We add the tare action
tare: this._barcodeTareAction,
});
}

async _barcodeTareAction(code) {
var last_orderline = this.currentOrder.get_last_orderline();
if (last_orderline) {
last_orderline.set_tare(code.value, true);
}
}

async _getAddProductOptions(product) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rewriting all this function is not a good option.
I think you can return weight + tare in the payload of the "ScaleScreen", and then overload _getAddProductOptions just to split the quantity field into the two weight and tare. What do you thing ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @legalsylvain and thanks for your comment.
As I remember I really tried not to do that but I didn't have the choice. I cannot tell you why exactly as I currently work on other projects and haven't touch this for months. If you are sure of you, you can maybe propose some changes and I'll gladly take a look (and test).

let price_extra = 0.0;
let draftPackLotLines, weight, description, packLotLinesToEdit, tare; // eslint-disable-line

if (
this.env.pos.config.product_configurator &&
_.some(
product.attribute_line_ids,
(id) => id in this.env.pos.attributes_by_ptal_id
)
) {
const attributes = _.map(
product.attribute_line_ids,
(id) => this.env.pos.attributes_by_ptal_id[id]
).filter((attr) => attr !== undefined);
const {confirmed, payload} = await this.showPopup(
"ProductConfiguratorPopup",
{
product: product,
attributes: attributes,
}
);

if (confirmed) {
description = payload.selected_attributes.join(", ");
price_extra += payload.price_extra;
} else {
return;
}
}

// Gather lot information if required.
if (
["serial", "lot"].includes(product.tracking) &&
(this.env.pos.picking_type.use_create_lots ||
this.env.pos.picking_type.use_existing_lots)
) {
const isAllowOnlyOneLot = product.isAllowOnlyOneLot();
if (isAllowOnlyOneLot) {
packLotLinesToEdit = [];
} else {
const orderline = this.currentOrder
.get_orderlines()
.filter((line) => !line.get_discount())
.find((line) => line.product.id === product.id);
if (orderline) {
packLotLinesToEdit = orderline.getPackLotLinesToEdit();
} else {
packLotLinesToEdit = [];
}
}
const {confirmed, payload} = await this.showPopup("EditListPopup", {
title: this.env._t("Lot/Serial Number(s) Required"),
isSingleItem: isAllowOnlyOneLot,
array: packLotLinesToEdit,
});
if (confirmed) {
// Segregate the old and new packlot lines
const modifiedPackLotLines = Object.fromEntries(
payload.newArray
.filter((item) => item.id)
.map((item) => [item.id, item.text])
);
const newPackLotLines = payload.newArray
.filter((item) => !item.id)
.map((item) => ({lot_name: item.text}));

draftPackLotLines = {modifiedPackLotLines, newPackLotLines};
} else {
// We don't proceed on adding product.
return;
}
}

// Take the weight if necessary.
if (product.to_weight && this.env.pos.config.iface_electronic_scale) {
// Show the ScaleScreen to weigh the product.
if (this.isScaleAvailable) {
const {confirmed, payload} = await this.showTempScreen(
"ScaleScreen",
{
product,
}
);
if (confirmed) {
// /////////////////////////////
// Overload Section
// We add the tare to the payload
// /////////////////////////////
weight = payload.weight;
tare = payload.tare;
} else {
// Do not add the product;
return;
}
} else {
await this._onScaleNotAvailable();
}
}

return {
draftPackLotLines,
quantity: weight,
description,
price_extra,
tare: tare,
};
}

_setValue(val) {
super._setValue(val);
if (this.currentOrder.get_selected_orderline()) {
if (this.state.numpadMode === "tare") {
if (this.env.pos.config.iface_tare_method === "barcode") {
this.showPopup("ErrorPopup", {
title: this.env._t("Feature Disabled"),
body: this.env._t(
"You can not set the tare." +
" To be able to set the tare manually" +
" you have to change the tare input method" +
" in the POS configuration"
),
});
} else {
try {
this.currentOrder
.get_selected_orderline()
.set_tare(val, true);
} catch (error) {
this.showPopup("ErrorPopup", {
title: this.env._t("We can not apply this tare"),
body: error.message,
});
}
}
}
}
}
};

Registries.Component.extend(ProductScreen, TareProductScreen);

return ProductScreen;
});
52 changes: 52 additions & 0 deletions pos_tare/static/src/js/Screens/ScaleScreen/ScaleScreen.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
odoo.define("pos_tare.ScaleScreen", function (require) {
"use strict";

const Registries = require("point_of_sale.Registries");
const ScaleScreen = require("point_of_sale.ScaleScreen");
const {useState} = owl.hooks;
const {useAutofocus} = require("web.custom_hooks");

const ColaborScaleScreen = (ScaleScreen) =>
class extends ScaleScreen {
constructor() {
super(...arguments);
this.state = useState({
tare: this.props.product.tare_weight,
weight: 0,
gross_weight: 0,
});
useAutofocus({selector: "#input_weight_tare"});
}

_readScale() {
if (this.env.pos.config.iface_gross_weight_method === "scale") {
super._readScale();
}
}

async _setWeight() {
await super._setWeight();
this.state.gross_weight = this.state.weight;
this.state.weight -= this.state.tare;
}

updateWeight() {
this.state.weight = this.state.gross_weight - this.state.tare;
}

confirm() {
this.props.resolve({
confirmed: true,
payload: {
weight: this.state.weight,
tare: this.state.tare,
},
});
this.trigger("close-temp-screen");
}
};

Registries.Component.extend(ScaleScreen, ColaborScaleScreen);

return ScaleScreen;
});
13 changes: 0 additions & 13 deletions pos_tare/static/src/js/db.js

This file was deleted.

23 changes: 15 additions & 8 deletions pos_tare/static/src/js/models.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
odoo.define("pos_tare.models", function (require) {
"use strict";
var core = require("web.core");
var models = require("point_of_sale.models");
models.load_fields("product.product", ["tare_weight"]);
var pos_tare_tools = require("pos_tare.tools");
var _t = core._t;

var _super_ = models.Orderline.prototype;
var _superOrder_ = models.Order.prototype;

var OrderWithTare = models.Order.extend({
add_product: function (product, options) {
var res = _superOrder_.add_product.call(this, product, options);
if (options.tare !== undefined) {
this.get_last_orderline().set_tare(options.tare);
}
return res;
},
});

var OrderLineWithTare = models.Orderline.extend({
// /////////////////////////////
// Overload Section
// /////////////////////////////

initialize: function (session, attributes) {
this.tare = 0;
return _super_.initialize.call(this, session, attributes);
Expand Down Expand Up @@ -65,11 +76,6 @@ odoo.define("pos_tare.models", function (require) {
tare_unit,
line_unit
);
var tare_in_product_uom_string = pos_tare_tools.format_tare(
this.pos,
tare_in_product_uom,
line_unit
);
if (update_net_weight) {
var net_quantity = this.get_quantity() - tare_in_product_uom;
// Update the quantity with the new weight net of tare quantity.
Expand Down Expand Up @@ -114,4 +120,5 @@ odoo.define("pos_tare.models", function (require) {
});

models.Orderline = OrderLineWithTare;
models.Order = OrderWithTare;
});
Loading
Loading