diff --git a/sale_order_blanket_order_stock_prebook_release/README.rst b/sale_order_blanket_order_stock_prebook_release/README.rst new file mode 100644 index 000000000000..7a8bb649575b --- /dev/null +++ b/sale_order_blanket_order_stock_prebook_release/README.rst @@ -0,0 +1,97 @@ +============================================== +Sale Order Blanket Order Stock Prebook Release +============================================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:3f68147daefc9ef868a5b6ba780abc44482618234844943c4d62564d0ba1351d + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsale--workflow-lightgray.png?logo=github + :target: https://github.com/OCA/sale-workflow/tree/16.0/sale_order_blanket_order_stock_prebook_release + :alt: OCA/sale-workflow +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/sale-workflow-16-0/sale-workflow-16-0-sale_order_blanket_order_stock_prebook_release + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/sale-workflow&target_branch=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module is a glue module between +sale_order_blanket_order_stock_prebook and +stock_available_to_promise_release + +**Table of contents** + +.. contents:: + :local: + +Use Cases / Context +=================== + +When a call-off order is confirmed for a product, the priority date used +to compute the available quantity available at promised date must be the +start date of the blanket order. + +This is required to ensure that the principle of first-come, +first-served is respected. In the case of a product part of a blanket +order the date to consider must be the start date of the blanket order +and not the date of the call-off order. + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* ACSONE SA/NV + +Contributors +------------ + +- Laurent Mignon laurent.mignon@acsone.eu (https://www.acsone.eu) + +Other credits +------------- + +The development of this module has been financially supported by: + +- ALCYON Belux + +Maintainers +----------- + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +This module is part of the `OCA/sale-workflow `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/sale_order_blanket_order_stock_prebook_release/__init__.py b/sale_order_blanket_order_stock_prebook_release/__init__.py new file mode 100644 index 000000000000..cc6b6354ad8f --- /dev/null +++ b/sale_order_blanket_order_stock_prebook_release/__init__.py @@ -0,0 +1,2 @@ +from . import models +from .hooks import post_init_hook diff --git a/sale_order_blanket_order_stock_prebook_release/__manifest__.py b/sale_order_blanket_order_stock_prebook_release/__manifest__.py new file mode 100644 index 000000000000..508c533bcc88 --- /dev/null +++ b/sale_order_blanket_order_stock_prebook_release/__manifest__.py @@ -0,0 +1,18 @@ +# Copyright 2025 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Sale Order Blanket Order Stock Prebook Release", + "summary": """Ensure that the date priotity when releasing""" + """ qty is the start date of the blanker order""", + "version": "16.0.1.0.0", + "license": "AGPL-3", + "author": "ACSONE SA/NV,Odoo Community Association (OCA)", + "website": "https://github.com/OCA/sale-workflow", + "depends": [ + "sale_order_blanket_order_stock_prebook", + "stock_available_to_promise_release", + ], + "auto_install": True, + "post_init_hook": "post_init_hook", +} diff --git a/sale_order_blanket_order_stock_prebook_release/hooks.py b/sale_order_blanket_order_stock_prebook_release/hooks.py new file mode 100644 index 000000000000..8ba3f695ba0a --- /dev/null +++ b/sale_order_blanket_order_stock_prebook_release/hooks.py @@ -0,0 +1,33 @@ +# Copyright 2025 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +import logging + +from odoo import SUPERUSER_ID, api + +_logger = logging.getLogger(__name__) + + +def post_init_hook(cr, registry): + """Create `account.payment.method` records + for the installed payment providers. + """ + _logger.info( + "Executing post init hook for module " + "sale_order_blanket_order_stock_prebook_release" + ) + env = api.Environment(cr, SUPERUSER_ID, {}) + blanket_orders = env["sale.order"].search( + [("order_type", "=", "blanket"), ("state", "in", ["sale", "done"])] + ) + + _logger.info( + f"Found {len(blanket_orders)} blanket orders to compute the move date priority" + ) + blanket_orders._compute_blanket_move_date_priority() + + _logger.info("Setting the move date priority for the blanket orders move lines") + for move_id in blanket_orders.order_line.move_ids: + if move_id.state not in ("done", "cancel", "assigned"): + move_id.date_priority = ( + move_id.sale_line_id.order_id.blanket_move_date_priority + ) diff --git a/sale_order_blanket_order_stock_prebook_release/models/__init__.py b/sale_order_blanket_order_stock_prebook_release/models/__init__.py new file mode 100644 index 000000000000..e7e9273fcff8 --- /dev/null +++ b/sale_order_blanket_order_stock_prebook_release/models/__init__.py @@ -0,0 +1,2 @@ +from . import sale_order_line +from . import sale_order diff --git a/sale_order_blanket_order_stock_prebook_release/models/sale_order.py b/sale_order_blanket_order_stock_prebook_release/models/sale_order.py new file mode 100644 index 000000000000..5394abbe7a16 --- /dev/null +++ b/sale_order_blanket_order_stock_prebook_release/models/sale_order.py @@ -0,0 +1,61 @@ +# Copyright 2025 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from collections import defaultdict +from datetime import timedelta + +from odoo import fields, models + + +class SaleOrder(models.Model): + + _inherit = "sale.order" + + blanket_move_date_priority = fields.Datetime( + string="Move Date Priority", + help="Date priority for the moves of the order.", + ) + + def action_confirm(self): + self._compute_blanket_move_date_priority() + return super().action_confirm() + + def _compute_blanket_move_date_priority(self): + """ + Compute the move date priority for the blanket orders. + + The move date priority for blanket orders is the validity start date of + the blanket order incremented by the position of the order according to + the confirmation date by blanket_validity_start_date. + This method is called at the start of the confirmation process. + """ + blankets = self.filtered(lambda o: o.order_type == "blanket") + # we need to query the count of confirmed blanket orders for each + # blanket_validity_start_date + if not blankets: + return + domain = [ + ( + "blanket_validity_start_date", + "in", + blankets.mapped("blanket_validity_start_date"), + ), + ("order_type", "=", "blanket"), + ("state", "in", ["sale", "done"]), + ] + res = self.env["sale.order"].read_group( + domain, + ["blanket_validity_start_date:group_count"], + ["blanket_validity_start_date"], + ) + count_per_date = defaultdict(int) + for data in res: + count_per_date[data["blanket_validity_start_date"]] = data[ + "blanket_validity_start_date_count" + ] + for order in blankets.sorted("create_date"): + start_date = order.blanket_validity_start_date + order_position = count_per_date.get(start_date, 0) + order.blanket_move_date_priority = start_date + timedelta( + seconds=order_position + ) + count_per_date[start_date] = order_position + 1 diff --git a/sale_order_blanket_order_stock_prebook_release/models/sale_order_line.py b/sale_order_blanket_order_stock_prebook_release/models/sale_order_line.py new file mode 100644 index 000000000000..ce45df723d1c --- /dev/null +++ b/sale_order_blanket_order_stock_prebook_release/models/sale_order_line.py @@ -0,0 +1,19 @@ +# Copyright 2025 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import models + + +class SaleOrderLine(models.Model): + + _inherit = "sale.order.line" + + def _prepare_procurement_values(self, group_id=False): + values = super()._prepare_procurement_values(group_id) + order = self.order_id + if ( + order.order_type == "blanket" + and order.blanket_reservation_strategy == "at_confirm" + ): + values["date_priority"] = order.blanket_move_date_priority + return values diff --git a/sale_order_blanket_order_stock_prebook_release/readme/CONTEXT.md b/sale_order_blanket_order_stock_prebook_release/readme/CONTEXT.md new file mode 100644 index 000000000000..ee12f38ed38d --- /dev/null +++ b/sale_order_blanket_order_stock_prebook_release/readme/CONTEXT.md @@ -0,0 +1,4 @@ +When a call-off order is confirmed for a product, the priority date used to compute the available quantity available at promised date must be the start date of the blanket order. + +This is required to ensure that the principle of first-come, first-served is respected. +In the case of a product part of a blanket order the date to consider must be the start date of the blanket order and not the date of the call-off order. \ No newline at end of file diff --git a/sale_order_blanket_order_stock_prebook_release/readme/CONTRIBUTORS.md b/sale_order_blanket_order_stock_prebook_release/readme/CONTRIBUTORS.md new file mode 100644 index 000000000000..a15e3ef244fc --- /dev/null +++ b/sale_order_blanket_order_stock_prebook_release/readme/CONTRIBUTORS.md @@ -0,0 +1 @@ +- Laurent Mignon (https://www.acsone.eu) diff --git a/sale_order_blanket_order_stock_prebook_release/readme/CREDITS.md b/sale_order_blanket_order_stock_prebook_release/readme/CREDITS.md new file mode 100644 index 000000000000..e7c5a535490d --- /dev/null +++ b/sale_order_blanket_order_stock_prebook_release/readme/CREDITS.md @@ -0,0 +1,3 @@ +The development of this module has been financially supported by: + +- ALCYON Belux diff --git a/sale_order_blanket_order_stock_prebook_release/readme/DESCRIPTION.md b/sale_order_blanket_order_stock_prebook_release/readme/DESCRIPTION.md new file mode 100644 index 000000000000..7ac9081b222a --- /dev/null +++ b/sale_order_blanket_order_stock_prebook_release/readme/DESCRIPTION.md @@ -0,0 +1 @@ +This module is a glue module between sale_order_blanket_order_stock_prebook and stock_available_to_promise_release \ No newline at end of file diff --git a/sale_order_blanket_order_stock_prebook_release/static/description/icon.png b/sale_order_blanket_order_stock_prebook_release/static/description/icon.png new file mode 100644 index 000000000000..3a0328b516c4 Binary files /dev/null and b/sale_order_blanket_order_stock_prebook_release/static/description/icon.png differ diff --git a/sale_order_blanket_order_stock_prebook_release/static/description/index.html b/sale_order_blanket_order_stock_prebook_release/static/description/index.html new file mode 100644 index 000000000000..7503e7f347d6 --- /dev/null +++ b/sale_order_blanket_order_stock_prebook_release/static/description/index.html @@ -0,0 +1,444 @@ + + + + + +Sale Order Blanket Order Stock Prebook Release + + + +
+

Sale Order Blanket Order Stock Prebook Release

+ + +

Beta License: AGPL-3 OCA/sale-workflow Translate me on Weblate Try me on Runboat

+

This module is a glue module between +sale_order_blanket_order_stock_prebook and +stock_available_to_promise_release

+

Table of contents

+ +
+

Use Cases / Context

+

When a call-off order is confirmed for a product, the priority date used +to compute the available quantity available at promised date must be the +start date of the blanket order.

+

This is required to ensure that the principle of first-come, +first-served is respected. In the case of a product part of a blanket +order the date to consider must be the start date of the blanket order +and not the date of the call-off order.

+
+
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • ACSONE SA/NV
  • +
+
+ +
+

Other credits

+

The development of this module has been financially supported by:

+
    +
  • ALCYON Belux
  • +
+
+
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

This module is part of the OCA/sale-workflow project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/test-requirements.txt b/test-requirements.txt index 66bc2cbae3f9..9fc1f8db36ca 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1 +1,5 @@ odoo_test_helper +odoo-addon-sale-stock-prebook @ git+https://github.com/OCA/sale-workflow.git@refs/pull/3481/head#subdirectory=setup/sale_stock_prebook +odoo-addon-sale-stock-prebook-stock-available-to_promise-release @ git+https://github.com/OCA/sale-workflow.git@refs/pull/3424/head#subdirectory=setup/sale_stock_prebook_stock_available_to_promise_release +odoo-addon-sale-order-blanket-order @ git+https://github.com/OCA/sale-workflow.git@refs/pull/3436/head#subdirectory=setup/sale_order_blanket_order +odoo-addon-sale-order-blanket-order-stock-prebook @ git+https://github.com/OCA/sale-workflow.git@refs/pull/3436/head#subdirectory=setup/sale_order_blanket_order_stock_prebook