-
-
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
f1277c7
commit d8232e8
Showing
15 changed files
with
496 additions
and
88 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
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
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
from . import lead_time_profile | ||
from . import res_company | ||
from . import res_config_settings | ||
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 |
---|---|---|
@@ -1,45 +1,90 @@ | ||
# Copyright 2025 Quartile | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
from odoo import fields, models | ||
from odoo import api, 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") | ||
warehouse_id = fields.Many2one( | ||
"stock.warehouse", help="Matched against the warehouse of the sales order." | ||
) | ||
partner_id = fields.Many2one( | ||
"res.partner", help="Matched against the delivery address of the sales order." | ||
) | ||
state_id = fields.Many2one( | ||
"res.country.state", domain="[('country_id', '=?', country_id)]" | ||
"res.country.state", | ||
domain="[('country_id', '=?', country_id)]", | ||
help="Matched against the state of the delivery address of the sales order.", | ||
) | ||
country_id = fields.Many2one( | ||
related="state_id.country_id", readonly=False, store=True, required=True | ||
"res.country", | ||
help="Matched against the country of the delivery address of the sales order.", | ||
) | ||
lead_time = fields.Float(required=True) | ||
company_id = fields.Many2one( | ||
"res.company", required=True, default=lambda self: self.env.company | ||
) | ||
lead_time = fields.Float(string="Lead Time (Days)", required=True) | ||
|
||
@api.onchange("partner_id") | ||
def _onchagnge_partner_id(self): | ||
for rec in self: | ||
if rec.partner_id: | ||
rec.state_id = rec.partner_id.state_id | ||
|
||
@api.onchange("state_id") | ||
def _onchagnge_state_id(self): | ||
for rec in self: | ||
if rec.partner_id.state_id != rec.state_id: | ||
rec.partner_id = False | ||
rec.country_id = rec.state_id.country_id | ||
|
||
@api.onchange("country_id") | ||
def _onchagnge_country_id(self): | ||
for rec in self: | ||
if rec.state_id.country_id != rec.country_id: | ||
rec.state_id = False | ||
if rec.partner_id.country_id != rec.country_id: | ||
rec.partner_id = False | ||
|
||
def _get_score(self, **kwargs): | ||
"""Return a matching score for this lead time profile. | ||
The method scores each relevant match (warehouse/country/state/partner) | ||
based on factors defined in the company. For example, if the partner matches, | ||
the score is increased by the factor_partner. If any mismatch is found, it | ||
immediately returns -1. | ||
def _get_score(self, warehouse, partner): | ||
:param kwargs: Dictionary containing 'warehouse' and 'partner'. | ||
:return: A float representing the total match score if no mismatch is found, | ||
or -1 if any mismatch is found. | ||
""" | ||
self.ensure_one() | ||
score = 0 | ||
if self.warehouse_id: | ||
if warehouse == self.warehouse_id: | ||
score += 1 | ||
else: | ||
return -1 | ||
partner = kwargs.get("partner") | ||
warehouse = kwargs.get("warehouse") | ||
company = self.company_id | ||
if self.partner_id: | ||
if partner == self.partner_id: | ||
score += 3 | ||
score += company.factor_partner | ||
else: | ||
return -1 | ||
elif self.state_id: | ||
if self.state_id: | ||
if partner.state_id == self.state_id: | ||
score += 2 | ||
score += company.factor_state | ||
else: | ||
return -1 | ||
elif self.country_id: | ||
if self.country_id: | ||
if partner.country_id == self.country_id: | ||
score += 1 | ||
score += company.factor_country | ||
else: | ||
return -1 | ||
if self.warehouse_id: | ||
if warehouse == self.warehouse_id: | ||
score += company.factor_warehouse | ||
else: | ||
return -1 | ||
return score |
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,13 @@ | ||
# Copyright 2025 Quartile | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
from odoo import fields, models | ||
|
||
|
||
class ResCompany(models.Model): | ||
_inherit = "res.company" | ||
|
||
factor_warehouse = fields.Float(default=1.0) | ||
factor_country = fields.Float(default=1.0) | ||
factor_state = fields.Float(default=1.0) | ||
factor_partner = fields.Float(default=1.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,24 @@ | ||
# Copyright 2025 Quartile | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
from odoo import fields, models | ||
|
||
|
||
class ResConfigSettings(models.TransientModel): | ||
_inherit = "res.config.settings" | ||
|
||
factor_warehouse = fields.Float( | ||
related="company_id.factor_warehouse", readonly=False | ||
) | ||
factor_country = fields.Float(related="company_id.factor_country", readonly=False) | ||
factor_state = fields.Float(related="company_id.factor_state", readonly=False) | ||
factor_partner = fields.Float(related="company_id.factor_partner", readonly=False) | ||
|
||
def open_lead_time_profile_list(self): | ||
self.ensure_one() | ||
return { | ||
"type": "ir.actions.act_window", | ||
"name": "Lead Time Profiles", | ||
"res_model": "lead.time.profile", | ||
"view_mode": "tree", | ||
} |
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
Oops, something went wrong.