-
-
Notifications
You must be signed in to change notification settings - Fork 602
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
Closed
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 354cca3
[REF] pos_tare: Black python code
legalsylvain db2d783
[MIG] pos_tare: Migration to 12.0
legalsylvain 34df026
[UPD] Update pos_tare.pot
oca-travis dc4f41e
[UPD] README.rst
OCA-git-bot 4690306
pos_tare 12.0.1.0.1
OCA-git-bot 09ba906
Added translation using Weblate (Spanish)
danimv5 fc3db49
Translated using Weblate (Spanish)
danimv5 0ac84d9
[UPD] Update pos_tare.pot
oca-travis 6508d9c
Update translation files
oca-transbot c6a8b79
[FIX] pos_tare : raise an error if the gross weight is not correct
legalsylvain 1aa252c
[FIX] pos_tare : move the confirm popup regarding null or negative qu…
legalsylvain ada6c5e
[UPD] Update pos_tare.pot
oca-travis e36c487
pos_tare 12.0.1.0.2
OCA-git-bot cc340a9
Update translation files
oca-transbot 61a3434
[UPD] Update pos_tare.pot
oca-travis 3ab0fd8
Update translation files
oca-transbot 64d85d0
[IMP][12.O] pos_tare : add default tare weight on product.template model
legalsylvain a7d165a
[UPD] Update pos_tare.pot
oca-travis ad8d038
[UPD] README.rst
OCA-git-bot 17558c8
pos_tare 12.0.1.0.3
OCA-git-bot 915d77e
Update translation files
oca-transbot 3c52604
[UPD] Update pos_tare.pot
oca-travis 68a40e2
Update translation files
oca-transbot 5a0a231
Added translation using Weblate (Italian)
mymage c393ff7
Translated using Weblate (Italian)
mymage 096f471
[IMP] pos_tare: black, isort, prettier
baimont 325ae22
[MIG] pos_tare: Migration to 14.0
baimont File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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).