Initial commit: Odoo 18.0-20251222 extra-addons
This commit is contained in:
1
account_invoice_supplier_ref_unique/models/__init__.py
Normal file
1
account_invoice_supplier_ref_unique/models/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import account_move, res_company, res_config_settings
|
||||
80
account_invoice_supplier_ref_unique/models/account_move.py
Normal file
80
account_invoice_supplier_ref_unique/models/account_move.py
Normal file
@@ -0,0 +1,80 @@
|
||||
# Copyright 2016 Acsone
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import api, fields, models
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
|
||||
class AccountMove(models.Model):
|
||||
_inherit = "account.move"
|
||||
|
||||
supplier_invoice_number = fields.Char(
|
||||
string="Vendor invoice number",
|
||||
readonly=True,
|
||||
copy=False,
|
||||
)
|
||||
|
||||
@api.constrains("supplier_invoice_number")
|
||||
def _check_unique_supplier_invoice_number_insensitive(self):
|
||||
"""
|
||||
Check if an other vendor bill has the same supplier_invoice_number
|
||||
and the same commercial_partner_id than the current instance
|
||||
"""
|
||||
for rec in self:
|
||||
if (
|
||||
rec.company_id.check_invoice_supplier_number
|
||||
and rec.supplier_invoice_number
|
||||
and rec.is_purchase_document(include_receipts=True)
|
||||
):
|
||||
same_supplier_inv_num = rec.search(
|
||||
[
|
||||
("commercial_partner_id", "=", rec.commercial_partner_id.id),
|
||||
("move_type", "in", ("in_invoice", "in_refund")),
|
||||
(
|
||||
"supplier_invoice_number",
|
||||
"=ilike",
|
||||
rec.supplier_invoice_number,
|
||||
),
|
||||
("id", "!=", rec.id),
|
||||
],
|
||||
limit=1,
|
||||
)
|
||||
if same_supplier_inv_num:
|
||||
raise ValidationError(
|
||||
self.env._(
|
||||
"The invoice/refund with supplier "
|
||||
"invoice number %(number)s "
|
||||
"already exists in Odoo under the number %(same)s "
|
||||
"for supplier %(supplier)s.",
|
||||
number=same_supplier_inv_num.supplier_invoice_number,
|
||||
same=same_supplier_inv_num.name or "-",
|
||||
supplier=same_supplier_inv_num.partner_id.display_name,
|
||||
)
|
||||
)
|
||||
|
||||
@api.onchange("supplier_invoice_number")
|
||||
def _onchange_supplier_invoice_number(self):
|
||||
if not self.ref:
|
||||
self.ref = self.supplier_invoice_number
|
||||
|
||||
def _reverse_moves(self, default_values_list=None, cancel=False):
|
||||
# OVERRIDE
|
||||
if default_values_list:
|
||||
for move, default_values in zip(self, default_values_list, strict=False):
|
||||
if (
|
||||
move
|
||||
and move.is_purchase_document(include_receipts=True)
|
||||
and default_values.get("ref")
|
||||
):
|
||||
default_values.update({"ref": ""})
|
||||
return super()._reverse_moves(
|
||||
default_values_list=default_values_list, cancel=cancel
|
||||
)
|
||||
|
||||
def copy(self, default=None):
|
||||
"""
|
||||
The unique vendor invoice number is not copied in vendor bills
|
||||
"""
|
||||
if self.is_purchase_document(include_receipts=True):
|
||||
default = dict(default or {}, ref="")
|
||||
return super().copy(default)
|
||||
13
account_invoice_supplier_ref_unique/models/res_company.py
Normal file
13
account_invoice_supplier_ref_unique/models/res_company.py
Normal file
@@ -0,0 +1,13 @@
|
||||
# Copyright 2023 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"
|
||||
|
||||
check_invoice_supplier_number = fields.Boolean(
|
||||
help="Check this if you want to constraint the unicity for Invoice Supplier"
|
||||
" Number",
|
||||
)
|
||||
@@ -0,0 +1,13 @@
|
||||
# Copyright 2023 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"
|
||||
|
||||
check_invoice_supplier_number = fields.Boolean(
|
||||
related="company_id.check_invoice_supplier_number",
|
||||
readonly=False,
|
||||
)
|
||||
Reference in New Issue
Block a user