Skip to content

Commit

Permalink
[ADD] sale_lead_time_profile
Browse files Browse the repository at this point in the history
  • Loading branch information
AungKoKoLin1997 committed Jan 17, 2025
1 parent 306ed10 commit 0ff8e28
Show file tree
Hide file tree
Showing 17 changed files with 802 additions and 0 deletions.
81 changes: 81 additions & 0 deletions sale_lead_time_profile/README.rst
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.
1 change: 1 addition & 0 deletions sale_lead_time_profile/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
17 changes: 17 additions & 0 deletions sale_lead_time_profile/__manifest__.py
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,
}
3 changes: 3 additions & 0 deletions sale_lead_time_profile/models/__init__.py
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
45 changes: 45 additions & 0 deletions sale_lead_time_profile/models/lead_time_profile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# 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"
_description = "Lead Time Profile"
_order = "country_id, state_id, partner_id, warehouse_id"

warehouse_id = fields.Many2one("stock.warehouse")
partner_id = fields.Many2one("res.partner", string="Delivery Address")
state_id = fields.Many2one(
"res.country.state", domain="[('country_id', '=?', country_id)]"
)
country_id = fields.Many2one(
related="state_id.country_id", readonly=False, store=True, required=True
)
lead_time = fields.Float(required=True)

def _get_score(self, warehouse, partner):
self.ensure_one()
score = 0
if self.warehouse_id:
if warehouse == self.warehouse_id:
score += 1
else:
return -1

Check warning on line 29 in sale_lead_time_profile/models/lead_time_profile.py

View check run for this annotation

Codecov / codecov/patch

sale_lead_time_profile/models/lead_time_profile.py#L29

Added line #L29 was not covered by tests
if self.partner_id:
if partner == self.partner_id:
score += 3

Check warning on line 32 in sale_lead_time_profile/models/lead_time_profile.py

View check run for this annotation

Codecov / codecov/patch

sale_lead_time_profile/models/lead_time_profile.py#L32

Added line #L32 was not covered by tests
else:
return -1
elif self.state_id:
if partner.state_id == self.state_id:
score += 2

Check warning on line 37 in sale_lead_time_profile/models/lead_time_profile.py

View check run for this annotation

Codecov / codecov/patch

sale_lead_time_profile/models/lead_time_profile.py#L37

Added line #L37 was not covered by tests
else:
return -1

Check warning on line 39 in sale_lead_time_profile/models/lead_time_profile.py

View check run for this annotation

Codecov / codecov/patch

sale_lead_time_profile/models/lead_time_profile.py#L39

Added line #L39 was not covered by tests
elif self.country_id:
if partner.country_id == self.country_id:
score += 1

Check warning on line 42 in sale_lead_time_profile/models/lead_time_profile.py

View check run for this annotation

Codecov / codecov/patch

sale_lead_time_profile/models/lead_time_profile.py#L42

Added line #L42 was not covered by tests
else:
return -1
return score

Check warning on line 45 in sale_lead_time_profile/models/lead_time_profile.py

View check run for this annotation

Codecov / codecov/patch

sale_lead_time_profile/models/lead_time_profile.py#L45

Added line #L45 was not covered by tests
37 changes: 37 additions & 0 deletions sale_lead_time_profile/models/sale_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# 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 expected for delivery from the warehouse to the delivery address.",
)

@api.depends("warehouse_id", "partner_shipping_id")
def _compute_delivery_lead_time(self):
for rec in self:
rec.delivery_lead_time = 0.0
if not rec.partner_shipping_id:
continue
profiles = self.env["lead.time.profile"].search(
[
"|",
("warehouse_id", "=", rec.warehouse_id.id),
("warehouse_id", "=", False),
]
)
if not profiles:
continue
best_profile = max(
profiles,
default=None,
key=lambda r: r._get_score(rec.warehouse_id, rec.partner_shipping_id),
)
rec.delivery_lead_time = best_profile.lead_time
25 changes: 25 additions & 0 deletions sale_lead_time_profile/models/sale_order_line.py
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
5 changes: 5 additions & 0 deletions sale_lead_time_profile/readme/CONFIGURE.rst
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.
2 changes: 2 additions & 0 deletions sale_lead_time_profile/readme/DESCRIPTION.rst
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.
2 changes: 2 additions & 0 deletions sale_lead_time_profile/security/ir.model.access.csv
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
Loading

0 comments on commit 0ff8e28

Please sign in to comment.