Skip to content

Commit

Permalink
[REF] pos_tare: do not rewrite _getAddProductOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
robinkeunen committed Jun 19, 2024
1 parent 325ae22 commit edd97c6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 108 deletions.
119 changes: 13 additions & 106 deletions pos_tare/static/src/js/Screens/ProductScreen/ProductScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,112 +22,19 @@ odoo.define("pos_tare.screens", function (require) {
}

async _getAddProductOptions(product) {
let price_extra = 0.0;
let draftPackLotLines, weight, description, packLotLinesToEdit, tare; // eslint-disable-line
return super._getAddProductOptions(product).then(
payload => {
if (!payload) return
if (!payload.quantity) return payload

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,
const {weight, tare} = payload.quantity
return {
...payload,
quantity: weight,
tare: tare,
}
);

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) {
Expand All @@ -139,9 +46,9 @@ odoo.define("pos_tare.screens", function (require) {
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"
" To be able to set the tare manually" +
" you have to change the tare input method" +
" in the POS configuration"
),
});
} else {
Expand Down
6 changes: 4 additions & 2 deletions pos_tare/static/src/js/Screens/ScaleScreen/ScaleScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ odoo.define("pos_tare.ScaleScreen", function (require) {
this.props.resolve({
confirmed: true,
payload: {
weight: this.state.weight,
tare: this.state.tare,
weight: {
weight: this.state.weight,
tare: this.state.tare ? parseFloat(this.state.tare): 0,
},
},
});
this.trigger("close-temp-screen");
Expand Down

0 comments on commit edd97c6

Please sign in to comment.