forked from OCA/pos
-
Notifications
You must be signed in to change notification settings - Fork 0
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
[REF] pos_lot_selection: Make it work properly on offline mode #4
Merged
nguyenminhchien
merged 1 commit into
nguyenminhchien:17.0-mig-pos_lot_selection
from
dixmit:17.0-mig-pos_lot_selection
Jan 17, 2024
Merged
Changes from all commits
Commits
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
from . import product_product | ||
from . import stock_lot | ||
|
||
from . import pos_session |
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,18 @@ | ||
# Copyright 2024 Dixmit | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import models | ||
|
||
|
||
class PosSession(models.Model): | ||
_inherit = "pos.session" | ||
|
||
def _loader_params_product_product(self): | ||
result = super()._loader_params_product_product() | ||
result["search_params"]["fields"].append("available_lot_for_pos_ids") | ||
return result | ||
|
||
def get_pos_ui_product_product_by_params(self, custom_search_params): | ||
return super( | ||
PosSession, self.with_company(self.company_id.id) | ||
).get_pos_ui_product_product_by_params(custom_search_params) |
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,48 @@ | ||
# Copyright 2022 Camptocamp SA | ||
# Copyright 2024 Dixmit | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) | ||
|
||
from odoo import api, fields, models | ||
from odoo.tools import float_compare | ||
|
||
|
||
class ProductProduct(models.Model): | ||
_inherit = "product.product" | ||
|
||
available_lot_for_pos_ids = fields.Json( | ||
compute="_compute_available_lot_for_pos", prefetch=False | ||
) | ||
|
||
@api.depends() | ||
@api.depends_context("company") | ||
def _compute_available_lot_for_pos(self): | ||
for record in self: | ||
record.available_lot_for_pos_ids = record.get_available_lots_for_pos( | ||
self.env.company.id | ||
) | ||
|
||
def get_available_lots_for_pos(self, company_id): | ||
self.ensure_one() | ||
if self.type != "product" or self.tracking == "none": | ||
return [] | ||
lots = ( | ||
self.env["stock.lot"] | ||
.sudo() | ||
.search( | ||
[ | ||
"&", | ||
["product_id", "=", self.id], | ||
"|", | ||
["company_id", "=", company_id], | ||
["company_id", "=", False], | ||
] | ||
) | ||
) | ||
|
||
lots = lots.filtered( | ||
lambda lot: float_compare( | ||
lot.product_qty, 0, precision_digits=lot.product_uom_id.rounding | ||
) | ||
> 0 | ||
) | ||
return [lot._get_pos_info() for lot in lots] |
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 |
---|---|---|
@@ -1,30 +1,16 @@ | ||
# Copyright 2022 Camptocamp SA | ||
# Copyright 2024 Dixmit | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) | ||
|
||
from odoo import api, models | ||
from odoo.tools import float_compare | ||
from odoo import models | ||
|
||
|
||
class ProductionLot(models.Model): | ||
class StockLot(models.Model): | ||
_inherit = "stock.lot" | ||
|
||
@api.model | ||
def get_available_lots_for_pos(self, product_id, company_id): | ||
lots = self.sudo().search( | ||
[ | ||
"&", | ||
["product_id", "=", product_id], | ||
"|", | ||
["company_id", "=", company_id], | ||
["company_id", "=", False], | ||
] | ||
) | ||
|
||
lots = lots.filtered( | ||
lambda rec: float_compare( | ||
rec.product_qty, 0, precision_digits=rec.product_uom_id.rounding | ||
) | ||
> 0 | ||
) | ||
|
||
return lots.mapped("name") | ||
def _get_pos_info(self): | ||
# We will add this as a hook to add more fields if necessary | ||
return { | ||
"id": self.id, | ||
"name": self.name, | ||
} |
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 |
---|---|---|
@@ -1,3 +1,10 @@ | ||
- Tecnativa | ||
- Camptocamp | ||
- Nguyen Minh Chien \<<chien@trobz.com>\> | ||
- Iryna Vyshnevska | ||
- Ivan Todorovich | ||
- Maksym Yankin | ||
- Dixmit | ||
- Enric Tobella | ||
- Tecnativa | ||
- David Vidal | ||
- Trobz Consulting | ||
- Nguyen Minh Chien <chien@trobz.com> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,52 @@ | ||
/** @odoo-module */ | ||
|
||
/* | ||
Copyright 2022 Camptocamp SA | ||
Copyright 2023 Dixmit | ||
Copyright 2022 Camptocamp | ||
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) | ||
*/ | ||
|
||
import {onWillStart, useState} from "@odoo/owl"; | ||
import {ConnectionLostError} from "@web/core/network/rpc_service"; | ||
import {EditListInput} from "@point_of_sale/app/store/select_lot_popup/edit_list_input/edit_list_input"; | ||
import {EditListPopup} from "@point_of_sale/app/store/select_lot_popup/select_lot_popup"; | ||
|
||
import {_t} from "@web/core/l10n/translation"; | ||
import {patch} from "@web/core/utils/patch"; | ||
import {session} from "@web/session"; | ||
|
||
patch(EditListInput.prototype, { | ||
get_lot_name(lot) { | ||
return lot.name; | ||
}, | ||
}); | ||
patch(EditListPopup.prototype, { | ||
setup() { | ||
super.setup(...arguments); | ||
super.setup(); | ||
this.data = useState({ | ||
lots: this.env.services.pos.selectedProduct.available_lot_for_pos_ids, | ||
}); | ||
onWillStart(this.onWillStart); | ||
}, | ||
async onWillStart() { | ||
if (this.props.title === _t("Lot/Serial Number(s) Required")) { | ||
this.props.lots = session.lots; | ||
// We keep this in order to ensure that this call is only done | ||
// when we add a serial | ||
try { | ||
const lots = await this.env.services.orm.call( | ||
"product.product", | ||
"get_available_lots_for_pos", | ||
[ | ||
[this.env.services.pos.selectedProduct.id], | ||
this.env.services.pos.company.id, | ||
] | ||
); | ||
this.data.lots = lots; | ||
this.env.services.pos.selectedProduct.available_lot_for_pos_ids = lots; | ||
} catch (error) { | ||
if (error instanceof ConnectionLostError) { | ||
return; | ||
} | ||
throw error; | ||
} | ||
} | ||
}, | ||
}); |
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,21 @@ | ||
/** @odoo-module */ | ||
|
||
/* | ||
Copyright 2022 Camptocamp SA | ||
Copyright 2023 Dixmit | ||
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) | ||
*/ | ||
|
||
import {PosStore} from "@point_of_sale/app/store/pos_store"; | ||
import {patch} from "@web/core/utils/patch"; | ||
import {session} from "@web/session"; | ||
import {Orderline, Product} from "@point_of_sale/app/store/models"; | ||
|
||
patch(PosStore.prototype, { | ||
async getProductLots(product) { | ||
try { | ||
return await this.orm.silent.call( | ||
"stock.lot", | ||
"get_available_lots_for_pos", | ||
[product.id, session.user_companies.current_company] | ||
); | ||
} catch (error) { | ||
console.error(error); | ||
return []; | ||
} | ||
import {patch} from "@web/core/utils/patch"; | ||
patch(Product.prototype, { | ||
getAddProductOptions() { | ||
this.pos.selectedProduct = this; | ||
return super.getAddProductOptions(...arguments); | ||
}, | ||
}); | ||
patch(Orderline.prototype, { | ||
editPackLotLines() { | ||
this.pos.selectedProduct = this.product; | ||
return super.editPackLotLines(...arguments); | ||
}, | ||
}); |
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
4 changes: 4 additions & 0 deletions
4
pos_lot_selection/static/tests/tours/LotSelection.tour.esm.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
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
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.
On the original code we had:
if self.type != "product" or self.tracking != "none":
Obviously it should be
self.tracking == "none"