-
-
Notifications
You must be signed in to change notification settings - Fork 602
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
376 additions
and
375 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
167 changes: 167 additions & 0 deletions
167
pos_tare/static/src/js/Screens/ProductScreen/ProductScreen.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | ||
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; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.