-
-
Notifications
You must be signed in to change notification settings - Fork 619
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from dixmit/17.0-mig-pos_lot_selection
[REF] pos_lot_selection: Make it work properly on offline mode
- Loading branch information
Showing
14 changed files
with
181 additions
and
94 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,9 +71,23 @@ Authors | |
Contributors | ||
------------ | ||
|
||
- Tecnativa | ||
- Camptocamp | ||
- Nguyen Minh Chien <[email protected]> | ||
|
||
- Iryna Vyshnevska | ||
- Ivan Todorovich | ||
- Maksym Yankin | ||
|
||
- Dixmit | ||
|
||
- Enric Tobella | ||
|
||
- Tecnativa | ||
|
||
- David Vidal | ||
|
||
- Trobz Consulting | ||
|
||
- Nguyen Minh Chien [email protected] | ||
|
||
Maintainers | ||
----------- | ||
|
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 \<<[email protected]>\> | ||
- Iryna Vyshnevska | ||
- Ivan Todorovich | ||
- Maksym Yankin | ||
- Dixmit | ||
- Enric Tobella | ||
- Tecnativa | ||
- David Vidal | ||
- Trobz Consulting | ||
- Nguyen Minh Chien <[email protected]> |
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