Skip to content
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

[16.0] [ADD] Sale Order Blanket Order Stock Prebook Release #3532

Draft
wants to merge 2 commits into
base: 16.0
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,17 @@ jobs:
name: test with OCB
makepot: "true"
- container: ghcr.io/oca/oca-ci/py3.10-odoo16.0:latest
exclude: "sale_packaging_default,sale_order_product_recommendation,sale_order_product_recommendation_packaging_default,sale_order_product_recommendation_elaboration"
exclude: "sale_packaging_default,sale_order_product_recommendation,sale_order_product_recommendation_packaging_default,sale_order_product_recommendation_elaboration,sale_order_blanket_order,sale_order_blanket_order_stock_prebook,sale_order_blanket_order_stock_prebook_release"
name: test with Odoo
- container: ghcr.io/oca/oca-ci/py3.10-ocb16.0:latest
exclude: "sale_packaging_default,sale_order_product_recommendation,sale_order_product_recommendation_packaging_default,sale_order_product_recommendation_elaboration"
exclude: "sale_packaging_default,sale_order_product_recommendation,sale_order_product_recommendation_packaging_default,sale_order_product_recommendation_elaboration,sale_order_blanket_order,sale_order_blanket_order_stock_prebook,sale_order_blanket_order_stock_prebook_release"
name: test with OCB
makepot: "true"
- container: ghcr.io/oca/oca-ci/py3.10-odoo16.0:latest
include: "sale_order_blanket_order,sale_order_blanket_order_stock_prebook,sale_order_blanket_order_stock_prebook_release"
name: test with Odoo
- container: ghcr.io/oca/oca-ci/py3.10-ocb16.0:latest
include: "sale_order_blanket_order,sale_order_blanket_order_stock_prebook,sale_order_blanket_order_stock_prebook_release"
name: test with OCB
makepot: "true"
services:
Expand Down Expand Up @@ -80,4 +87,4 @@ jobs:
token: ${{ secrets.CODECOV_TOKEN }}
- name: Update .pot files
run: oca_export_and_push_pot https://x-access-token:${{ secrets.GIT_PUSH_TOKEN }}@github.com/${{ github.repository }}
if: ${{ matrix.makepot == 'true' && github.event_name == 'push' && github.repository_owner == 'OCA' }}
if: ${{ matrix.makepot == 'true' && github.event_name == 'push' && github.repository_owner == 'OCA' }}
97 changes: 97 additions & 0 deletions sale_order_blanket_order_stock_prebook_release/README.rst
Original file line number Diff line number Diff line change
@@ -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 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 <https://github.com/OCA/sale-workflow/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 <https://github.com/OCA/sale-workflow/issues/new?body=module:%20sale_order_blanket_order_stock_prebook_release%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

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

Credits
=======

Authors
-------

* ACSONE SA/NV

Contributors
------------

- Laurent Mignon [email protected] (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 <https://github.com/OCA/sale-workflow/tree/16.0/sale_order_blanket_order_stock_prebook_release>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 2 additions & 0 deletions sale_order_blanket_order_stock_prebook_release/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import models
from .hooks import post_init_hook
18 changes: 18 additions & 0 deletions sale_order_blanket_order_stock_prebook_release/__manifest__.py
Original file line number Diff line number Diff line change
@@ -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",
}
33 changes: 33 additions & 0 deletions sale_order_blanket_order_stock_prebook_release/hooks.py
Original file line number Diff line number Diff line change
@@ -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
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import sale_order_line
from . import sale_order
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Copyright 2025 ACSONE SA/NV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
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.flush_recordset()
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

# we must use plain SQL to avoid the transformation of date and datetime
# fields to strings done by the read_group method which is designed to
# be use to display data in a view... :-(
query = """
SELECT
blanket_validity_start_date,
count(1)
FROM
sale_order
WHERE
order_type = 'blanket'
AND state in ('sale', 'done')
AND blanket_validity_start_date in %s
GROUP BY blanket_validity_start_date
"""
self.env.cr.execute(
query, (tuple(blankets.mapped("blanket_validity_start_date")),)
)
count_per_date = dict(self.env.cr.fetchall())
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 = fields.Datetime.to_datetime(
start_date
) + timedelta(seconds=order_position)
count_per_date[start_date] = order_position + 1
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
When a call-off order is confirmed for a product, the priority date used to compute the 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.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Laurent Mignon <[email protected]> (https://www.acsone.eu)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
The development of this module has been financially supported by:

- ALCYON Belux
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This module is a glue module between sale_order_blanket_order_stock_prebook and stock_available_to_promise_release
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading