diff --git a/account_invoice_structured_ref_be/__init__.py b/account_invoice_structured_ref_be/__init__.py new file mode 100644 index 0000000..a0fdc10 --- /dev/null +++ b/account_invoice_structured_ref_be/__init__.py @@ -0,0 +1,2 @@ +# -*- coding: utf-8 -*- +from . import models diff --git a/account_invoice_structured_ref_be/__manifest__.py b/account_invoice_structured_ref_be/__manifest__.py new file mode 100644 index 0000000..74715a0 --- /dev/null +++ b/account_invoice_structured_ref_be/__manifest__.py @@ -0,0 +1,13 @@ +# -*- coding: utf-8 -*- +{ + 'name': 'Belgian Structured Invoice Reference', + 'version': '16.0.1.0.0', + 'summary': 'Adds "Based on Invoice Number (BE Structured)" communication type for Belgian OGM/VCS references', + 'category': 'Accounting/Localizations', + 'author': 'Busenco', + 'depends': ['account', 'l10n_be'], + 'data': [], + 'installable': True, + 'auto_install': False, + 'license': 'LGPL-3', +} diff --git a/account_invoice_structured_ref_be/models/__init__.py b/account_invoice_structured_ref_be/models/__init__.py new file mode 100644 index 0000000..8ea1d8f --- /dev/null +++ b/account_invoice_structured_ref_be/models/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- +from . import account_journal +from . import account_move diff --git a/account_invoice_structured_ref_be/models/account_journal.py b/account_invoice_structured_ref_be/models/account_journal.py new file mode 100644 index 0000000..7b699ae --- /dev/null +++ b/account_invoice_structured_ref_be/models/account_journal.py @@ -0,0 +1,11 @@ +# -*- coding: utf-8 -*- +from odoo import fields, models + + +class AccountJournal(models.Model): + _inherit = 'account.journal' + + invoice_reference_type = fields.Selection( + selection_add=[('be_structured', 'Based on Invoice Number (BE Structured)')], + ondelete={'be_structured': 'set default'}, + ) diff --git a/account_invoice_structured_ref_be/models/account_move.py b/account_invoice_structured_ref_be/models/account_move.py new file mode 100644 index 0000000..ad74d02 --- /dev/null +++ b/account_invoice_structured_ref_be/models/account_move.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- +import re +from odoo import models + + +class AccountMove(models.Model): + _inherit = 'account.move' + + def _get_invoice_reference_be_structured(self): + """Compute a Belgian structured communication (OGM/VCS) from the invoice name. + + 1. Strip all non-digit characters from the invoice name. + 2. Zero-pad left to 10 digits. + 3. Check digits = (number % 97) or 97 if result is 0, zero-padded to 2 digits. + 4. Format: +++XXX/XXXX/XXXCC+++ (positions 0-2, 3-6, 7-9, then 2-digit check). + """ + self.ensure_one() + digits = re.sub(r'\D', '', self.name or '').zfill(10) + check = int(digits) % 97 or 97 + cc = str(check).zfill(2) + return '+++{}/{}/{}{}+++'.format(digits[0:3], digits[3:7], digits[7:10], cc) + + def _get_invoice_computed_reference(self): + self.ensure_one() + if self.journal_id.invoice_reference_type == 'be_structured': + return self._get_invoice_reference_be_structured() + return super()._get_invoice_computed_reference()