-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
306ed10
commit e9a7924
Showing
17 changed files
with
783 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,81 @@ | ||
====================== | ||
Sale Lead Time Profile | ||
====================== | ||
|
||
.. | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! source digest: sha256:79be59475657d45c9881f4693df4e99894b904631029a20ab08f12cbfa64d303 | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
.. |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_lead_time_profile | ||
: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_lead_time_profile | ||
: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 enhances the sales order process by adding a delivery_lead_time that is determined based on the most closely matching lead time profile. | ||
This time is then incorporated into the customer_lead of each sale order line, optimizing delivery scheduling based on specific lead time configurations. | ||
|
||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
Configuration | ||
============= | ||
|
||
To configure this module, you must first properly set up your lead time profiles: | ||
|
||
1. Navigate to Inventory > Configuration > Lead Time Profiles. | ||
2. Create the records according to your specific requirements. | ||
The system will use the most matching record to determine the delivery lead time for each sale 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_lead_time_profile%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 | ||
~~~~~~~ | ||
|
||
* Quartile | ||
|
||
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_lead_time_profile>`_ project on GitHub. | ||
|
||
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. |
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 @@ | ||
from . import models |
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,17 @@ | ||
# Copyright 2025 Quartile | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
{ | ||
"name": "Sale Lead Time Profile", | ||
"version": "16.0.1.0.0", | ||
"author": "Quartile, Odoo Community Association (OCA)", | ||
"website": "https://github.com/OCA/sale-workflow", | ||
"license": "AGPL-3", | ||
"depends": ["sale_stock"], | ||
"data": [ | ||
"security/ir.model.access.csv", | ||
"views/lead_time_profile_views.xml", | ||
"views/sale_order_views.xml", | ||
], | ||
"installable": True, | ||
} |
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,3 @@ | ||
from . import lead_time_profile | ||
from . import sale_order | ||
from . import sale_order_line |
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,23 @@ | ||
# Copyright 2025 Quartile | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
from odoo import fields, models | ||
|
||
|
||
class LeadTimeProfile(models.Model): | ||
_name = "lead.time.profile" | ||
|
||
warehouse_id = fields.Many2one("stock.warehouse", required=True) | ||
partner_id = fields.Many2one( | ||
"res.partner", string="Delivery Address", domain="[('type', '=', 'delivery')]" | ||
) | ||
state_id = fields.Many2one( | ||
related="partner_id.state_id", | ||
readonly=False, | ||
store=True, | ||
domain="[('country_id', '=?', country_id)]", | ||
) | ||
country_id = fields.Many2one( | ||
related="partner_id.country_id", readonly=False, store=True | ||
) | ||
lead_time = fields.Float(required=True) |
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,41 @@ | ||
# Copyright 2025 Quartile | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
from odoo import api, fields, models | ||
|
||
|
||
class SaleOrder(models.Model): | ||
_inherit = "sale.order" | ||
|
||
delivery_lead_time = fields.Float( | ||
compute="_compute_delivery_lead_time", | ||
store=True, | ||
readonly=False, | ||
help="Number of days to add to the lead time of the sale order line.", | ||
) | ||
|
||
def _find_best_matching_profile(self, profiles, order): | ||
best_score = -1 | ||
best_profile = None | ||
for profile in profiles: | ||
score = 0 | ||
if profile.partner_id == order.partner_shipping_id: | ||
score += 1 | ||
if profile.state_id == order.partner_shipping_id.state_id: | ||
score += 1 | ||
if profile.country_id == order.partner_shipping_id.country_id: | ||
score += 1 | ||
if score > best_score: | ||
best_score = score | ||
best_profile = profile | ||
return best_profile | ||
|
||
@api.depends("warehouse_id", "partner_id") | ||
def _compute_delivery_lead_time(self): | ||
for rec in self: | ||
# Assume only the matched warehouse_id is used | ||
profiles = self.env["lead.time.profile"].search( | ||
[("warehouse_id", "=", rec.warehouse_id.id)] | ||
) | ||
best_profile = self._find_best_matching_profile(profiles, rec) | ||
rec.delivery_lead_time = best_profile.lead_time if best_profile else 0.0 |
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,25 @@ | ||
# Copyright 2025 Quartile | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
from datetime import timedelta | ||
|
||
from odoo import api, models | ||
|
||
|
||
class SaleOrderLine(models.Model): | ||
_inherit = "sale.order.line" | ||
|
||
@api.depends("product_id", "order_id.delivery_lead_time") | ||
def _compute_customer_lead(self): | ||
super()._compute_customer_lead() | ||
for line in self: | ||
line.customer_lead += line.order_id.delivery_lead_time | ||
return | ||
|
||
def _prepare_procurement_values(self, group_id=False): | ||
values = super()._prepare_procurement_values(group_id) | ||
if values.get("date_planned"): | ||
values["date_planned"] = values["date_planned"] - timedelta( | ||
days=self.order_id.delivery_lead_time | ||
) | ||
return values |
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,5 @@ | ||
To configure this module, you must first properly set up your lead time profiles: | ||
|
||
1. Navigate to Inventory > Configuration > Lead Time Profiles. | ||
2. Create the records according to your specific requirements. | ||
The system will use the most matching record to determine the delivery lead time for each sale order. |
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,2 @@ | ||
This module enhances the sales order process by adding a delivery_lead_time that is determined based on the most closely matching lead time profile. | ||
This time is then incorporated into the customer_lead of each sale order line, optimizing delivery scheduling based on specific lead time configurations. |
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,2 @@ | ||
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink | ||
access_lead_time_profile,lead.time.profile,model_lead_time_profile,sales_team.group_sale_manager,1,1,1,1 |
Oops, something went wrong.