Add Belgian structured communication (OGM/VCS) invoice reference type

This commit is contained in:
Kristof Bernaert
2026-04-13 18:16:24 +02:00
parent 16da61111b
commit d24a769000
5 changed files with 56 additions and 0 deletions
@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-
from . import account_journal
from . import account_move
@@ -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'},
)
@@ -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()