-
-
Notifications
You must be signed in to change notification settings - Fork 685
[18.0][IMP] pos_sale_picking_keep: Add a strategy to keep sale pickings and/or POS pickings too #1545
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
base: 18.0
Are you sure you want to change the base?
[18.0][IMP] pos_sale_picking_keep: Add a strategy to keep sale pickings and/or POS pickings too #1545
Changes from all commits
4b7ed8e
cfb40d8
f945608
f32ffd4
2d43560
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| # Copyright 2026 ACSONE SA/NV | ||
| # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
| from odoo import fields, models | ||
|
|
||
|
|
||
| class PosConfig(models.Model): | ||
| _inherit = "pos.config" | ||
|
|
||
| keep_picking = fields.Boolean( | ||
| help="When loading sale orders in POS, Odoo cancels the sale pickings." | ||
| "Change the strategy here.", | ||
| ) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| # Copyright 2026 ACSONE SA/NV | ||
| # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
| from odoo import models | ||
|
|
||
|
|
||
| class PosOrderLine(models.Model): | ||
| _inherit = "pos.order.line" | ||
|
|
||
| def _launch_stock_rule_from_pos_order_lines(self): | ||
| """ | ||
| Launch stock rules for pos order lines that are not linked to a sale order | ||
| line and when the strategy is to keep both pos and sale order pickings | ||
| """ | ||
| lines_to_launch = self.filtered( | ||
| lambda line: not line.order_id.pos_config.keep_picking | ||
| or ( | ||
| line.order_id.pos_config.picking_keep_strategy | ||
| == "keep_sale_pos_pickings" | ||
| and not line.sale_order_line_id | ||
| ) | ||
| ) | ||
| if lines_to_launch: | ||
| super( | ||
| PosOrderLine, lines_to_launch | ||
| )._launch_stock_rule_from_pos_order_lines() | ||
| return True |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| # Copyright 2026 ACSONE SA/NV | ||
| # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
| from odoo import fields, models | ||
|
|
||
|
|
||
| class ResConfigSettings(models.TransientModel): | ||
| _inherit = "res.config.settings" | ||
|
|
||
| pos_keep_picking = fields.Boolean( | ||
| related="pos_config_id.keep_picking", | ||
| readonly=False, | ||
| ) |
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,19 +1,42 @@ | ||||||||||||||
| # Copyright 2026 Tecnativa - Víctor Martínez | ||||||||||||||
| # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||||||||||||||
| from odoo import api, models | ||||||||||||||
| from odoo import models | ||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
| class SaleOrderLine(models.Model): | ||||||||||||||
| _inherit = "sale.order.line" | ||||||||||||||
|
|
||||||||||||||
| # TODO: Delete if merged https://github.com/odoo/odoo/pull/253333 | ||||||||||||||
| def _compute_qty_delivered(self): | ||||||||||||||
| self = self.with_context(from_qty_delivered=True) | ||||||||||||||
| return super()._compute_qty_delivered() | ||||||||||||||
| res = super()._compute_qty_delivered() | ||||||||||||||
|
|
||||||||||||||
| # TODO: Delete if merged https://github.com/odoo/odoo/pull/253333 | ||||||||||||||
| @api.model | ||||||||||||||
| def _convert_qty(self, sale_line, qty, direction): | ||||||||||||||
| if self.env.context.get("from_qty_delivered"): | ||||||||||||||
| return 0 | ||||||||||||||
| return super()._convert_qty(sale_line=sale_line, qty=qty, direction=direction) | ||||||||||||||
| # Mimic what is done at pos_sale level but lowering the quantity | ||||||||||||||
| # TODO: Delete if merged https://github.com/odoo/odoo/pull/253333 | ||||||||||||||
| def update_qty_delivered_from_pickings(sale_line, pos_lines): | ||||||||||||||
| if all( | ||||||||||||||
| picking.state == "done" for picking in pos_lines.order_id.picking_ids | ||||||||||||||
| ): | ||||||||||||||
|
Comment on lines
+15
to
+17
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure if we should prevent empty list (
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @petrus-v Oh yes, wrong copy paste 😓
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @petrus-v In fact, no. We should wait : odoo/odoo#253333 |
||||||||||||||
| sale_line.qty_delivered -= sum( | ||||||||||||||
| ( | ||||||||||||||
| self._convert_qty(sale_line, pos_line.qty, "p2s") | ||||||||||||||
| for pos_line in pos_lines | ||||||||||||||
| if sale_line.product_id.type != "service" | ||||||||||||||
| ), | ||||||||||||||
| 0, | ||||||||||||||
| ) | ||||||||||||||
|
|
||||||||||||||
| for sale_line in self: | ||||||||||||||
| if sale_line.pos_order_line_ids.order_id.config_id.keep_picking: | ||||||||||||||
| pos_lines = sale_line.pos_order_line_ids.filtered( | ||||||||||||||
| lambda order_line: order_line.order_id.state | ||||||||||||||
| not in ["cancel", "draft"] | ||||||||||||||
| ) | ||||||||||||||
| update_qty_delivered_from_pickings(sale_line, pos_lines) | ||||||||||||||
|
|
||||||||||||||
| refund_lines = ( | ||||||||||||||
| sale_line.pos_order_line_ids.refund_orderline_ids.filtered( | ||||||||||||||
| lambda order_line: order_line.order_id.state | ||||||||||||||
| not in ["cancel", "draft"] | ||||||||||||||
| ) | ||||||||||||||
| ) | ||||||||||||||
| update_qty_delivered_from_pickings(sale_line, refund_lines) | ||||||||||||||
| return res | ||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| # Copyright 2026 ACSONE SA/NV | ||
| # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
| from odoo import api, models | ||
|
|
||
|
|
||
| class StockPicking(models.Model): | ||
| _inherit = "stock.picking" | ||
|
|
||
| @api.model | ||
| def _create_picking_from_pos_order_lines( | ||
| self, location_dest_id, lines, picking_type, partner=False | ||
| ): | ||
| """ | ||
| Avoid cancelling existing pickings and re-launching stock rules from | ||
| POS line if linked to a sale order line and with a strategy | ||
| to keep sale pickings. | ||
| """ | ||
| lines_without_create = lines.filtered( | ||
| lambda line: line.sale_order_line_id | ||
| and line.order_id.config_id.keep_picking | ||
| ) | ||
| return super()._create_picking_from_pos_order_lines( | ||
| location_dest_id=location_dest_id, | ||
| lines=(lines - lines_without_create), | ||
| picking_type=picking_type, | ||
| partner=partner, | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| - [Tecnativa](https://www.tecnativa.com) | ||
| - Pedro M. Baeza | ||
| - Víctor Martínez | ||
|
|
||
| - [ACSONE SA/NV](https://acsone.eu): | ||
| - Denis Roussel \<<denis.roussel@acsone.eu>\> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| from . import test_pos_sale_picking_keep | ||
| from . import test_pos_sale_picking_keep_realtime |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| # Copyright 2026 Tecnativa - Víctor Martínez | ||
| # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
| import odoo.tests | ||
|
|
||
| from odoo.addons.point_of_sale.tests.test_frontend import TestPointOfSaleHttpCommon | ||
|
|
||
|
|
||
| @odoo.tests.tagged("post_install", "-at_install") | ||
| class PosSalePickingKeepCommon(TestPointOfSaleHttpCommon): | ||
| @classmethod | ||
| def setUpClass(cls): | ||
| super().setUpClass() | ||
| cls.main_pos_config.keep_picking = True | ||
| cls.customer = cls.env["res.partner"].create({"name": "Test partner"}) | ||
| cls.warehouse = cls.env["stock.warehouse"].search( | ||
| [("company_id", "=", cls.env.company.id)], limit=1 | ||
| ) | ||
| cls.product = cls.env["product.product"].create( | ||
| { | ||
| "name": "Test Product", | ||
| "available_in_pos": True, | ||
| "is_storable": True, | ||
| "lst_price": 10.0, | ||
| } | ||
| ) | ||
| cls.product_2 = cls.env["product.product"].create( | ||
| { | ||
| "name": "Test Product 2", | ||
| "available_in_pos": True, | ||
| "is_storable": True, | ||
| "lst_price": 10.0, | ||
| } | ||
| ) | ||
| cls.main_pos_config.name = "test_pos_sale_picking_keep" |
Uh oh!
There was an error while loading. Please reload this page.