Initial commit: Odoo 18.0-20251222 extra-addons
This commit is contained in:
4
sale_partner_address_restrict/models/__init__.py
Executable file
4
sale_partner_address_restrict/models/__init__.py
Executable file
@@ -0,0 +1,4 @@
|
||||
from . import sale_order
|
||||
from . import res_company
|
||||
from . import res_partner
|
||||
from . import res_config_settings
|
||||
13
sale_partner_address_restrict/models/res_company.py
Executable file
13
sale_partner_address_restrict/models/res_company.py
Executable file
@@ -0,0 +1,13 @@
|
||||
# Copyright 2024 ACSONE SA/NV
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class ResCompany(models.Model):
|
||||
_inherit = "res.company"
|
||||
|
||||
sale_partner_address_restriction = fields.Boolean(
|
||||
help="Check this box if you want to restrict partner addresses selection "
|
||||
"in sale orders. They should depends on the Customer filled in."
|
||||
)
|
||||
13
sale_partner_address_restrict/models/res_config_settings.py
Executable file
13
sale_partner_address_restrict/models/res_config_settings.py
Executable file
@@ -0,0 +1,13 @@
|
||||
# Copyright 2024 ACSONE SA/NV
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class ResConfigSettings(models.TransientModel):
|
||||
_inherit = "res.config.settings"
|
||||
|
||||
sale_partner_address_restriction = fields.Boolean(
|
||||
related="company_id.sale_partner_address_restriction",
|
||||
readonly=False,
|
||||
)
|
||||
16
sale_partner_address_restrict/models/res_partner.py
Executable file
16
sale_partner_address_restrict/models/res_partner.py
Executable file
@@ -0,0 +1,16 @@
|
||||
# Copyright 2025 ForgeFlow S.L.
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class ResPartner(models.Model):
|
||||
_inherit = "res.partner"
|
||||
|
||||
is_dropship_address = fields.Boolean(string="Dropship Address")
|
||||
|
||||
def _get_complete_name(self):
|
||||
res = super()._get_complete_name()
|
||||
if not self.is_dropship_address or not self.name or not self.type == "delivery":
|
||||
return res
|
||||
return self.name.strip()
|
||||
49
sale_partner_address_restrict/models/sale_order.py
Executable file
49
sale_partner_address_restrict/models/sale_order.py
Executable file
@@ -0,0 +1,49 @@
|
||||
from odoo import _, api, fields, models
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
|
||||
class SaleOrder(models.Model):
|
||||
_inherit = "sale.order"
|
||||
|
||||
partner_address_restriction_domain = fields.Binary(
|
||||
compute="_compute_partner_address_restriction_domain",
|
||||
help="This is the computed domain to filter delivery and invoicing addresses.",
|
||||
)
|
||||
|
||||
@api.depends("partner_id", "company_id.sale_partner_address_restriction")
|
||||
def _compute_partner_address_restriction_domain(self):
|
||||
for activated, activated_sales in self.partition(
|
||||
lambda sale: sale.company_id.sale_partner_address_restriction
|
||||
).items():
|
||||
if not activated:
|
||||
activated_sales.partner_address_restriction_domain = [(1, "=", 1)]
|
||||
continue
|
||||
for company, sales in activated_sales.partition("company_id").items():
|
||||
for sale in sales:
|
||||
sale.partner_address_restriction_domain = [
|
||||
("commercial_partner_id", "=", sale.partner_id.id),
|
||||
"|",
|
||||
("company_id", "=", False),
|
||||
("company_id", "=", company.id),
|
||||
]
|
||||
|
||||
@api.constrains("partner_id", "partner_invoice_id", "partner_shipping_id")
|
||||
def _check_partner_addresses(self):
|
||||
for order in self:
|
||||
if (
|
||||
order.company_id.sale_partner_address_restriction
|
||||
and order.partner_id
|
||||
and (
|
||||
(order.partner_invoice_id.commercial_partner_id != order.partner_id)
|
||||
or (
|
||||
order.partner_shipping_id.commercial_partner_id
|
||||
!= order.partner_id
|
||||
)
|
||||
)
|
||||
):
|
||||
raise ValidationError(
|
||||
_(
|
||||
"Invoice and shipping addresses must be child addresses"
|
||||
" of the selected partner or the selected partner itself."
|
||||
)
|
||||
)
|
||||
Reference in New Issue
Block a user