Files
Odoo-18.0-20251222/partner_invoicing_mode_at_shipping/models/res_partner.py
tocmo0nlord adbe430761
Some checks failed
pre-commit / pre-commit (push) Has been cancelled
tests / Detect unreleased dependencies (push) Has been cancelled
tests / test with OCB (push) Has been cancelled
tests / test with Odoo (push) Has been cancelled
Initial commit: Odoo 18.0-20251222 extra-addons
2026-03-13 20:43:25 +00:00

52 lines
1.8 KiB
Python

# Copyright 2020 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)
from odoo import api, fields, models
from odoo.exceptions import ValidationError
class ResPartner(models.Model):
_inherit = "res.partner"
invoicing_mode = fields.Selection(
selection_add=[("at_shipping", "At Shipping")],
ondelete={"at_shipping": "set default"},
)
one_invoice_per_shipping = fields.Boolean(
index=True,
help="Check this if you want to create one invoice per shipping using the"
" partner invoicing mode that should be different than 'At Shipping'.",
)
@api.model
def _commercial_fields(self):
return super()._commercial_fields() + [
"one_invoice_per_shipping",
]
@api.constrains(
"invoicing_mode", "one_invoice_per_shipping", "one_invoice_per_order"
)
def _check_invoicing_mode_one_invoice_per_shipping(self):
for partner in self:
if (
partner.invoicing_mode == "at_shipping"
and partner.one_invoice_per_shipping
):
raise ValidationError(
self.env._(
"You cannot configure the partner %(partner)s with "
"Invoicing Mode 'At Shipping' and 'One Invoice Per Shipping'!",
partner=partner.name,
),
)
if partner.one_invoice_per_shipping and partner.one_invoice_per_order:
raise ValidationError(
self.env._(
"You cannot configure the partner %(partner)s with "
"'One Invoice Per Order' and 'One Invoice Per Shipping'!",
partner=partner.name,
),
)