Skip to Content
Menu
This question has been flagged
1 Atsakyti
582 Rodiniai

On odoo 18.0, odoo has checked on account code, they not allow hypens on account code ex. 1000-01


As I checked on commit they said

The new account report engine requires account codes to only contain alphanumeric characters and dots.
Add two new constrains on account_account and account_account_template to block the creation of accounts with codes that would cause issues in account reports.
ACCOUNT_CODE_REGEX = re.compile(r'^[A-Za-z0-9.]+$')

@api.constrains('code')
def _check_account_code(self):
        for account in self:
            if not re.match(ACCOUNT_CODE_REGEX, account.code):
                raise ValidationError(_(
                    "The account code can only contain alphanumeric characters and dots."
                ))


Have any suggestion if I want to use account code like 1000-01, 2100-22


Thanks in advance.

Portretas
Atmesti
Best Answer

Hi,

The reporting engine in v18 builds dynamic groups and hierarchies based on account codes. Allowing special characters (like -) breaks the parser for ranges, intervals, and hierarchical structures. That’s why Odoo made this stricter — it simplifies grouping and avoids bugs in financial reports.


1-Recommended approach (adapt codes):

Replace hyphens with dots or numbers. For example:


    1000-01 → 1000.01


    2100-22 → 2100.22


2- If your client insists on using hyphens, you can override the constraint in a custom addon. Example:


from odoo import api, models


class AccountAccount(models.Model):

    _inherit = "account.account"


    @api.constrains('code')

    def _check_account_code(self):

        # Override: allow hyphens too

        for account in self:

            if not re.match(r'^[A-Za-z0-9.-]+$', account.code):

                raise ValidationError(

                    "The account code can only contain alphanumeric characters, dots and hyphens."

                )

Downside: You’ll have to patch the reporting engine as well, because the default grouping logic may not handle -. This means you might run into errors when printing general ledger, trial balance, or consolidated reports.


3- Keep the official account code in Odoo without the hyphen (e.g. 100001) but add a custom field for the “legacy code” with hyphens (for display/printing). This way you stay compliant with Odoo’s constraints, but users still see the familiar format on reports.



Hope it helps

Portretas
Atmesti
Related Posts Replies Rodiniai Veikla
1
spal. 25
1177
0
spal. 25
132
2
spal. 25
261
1
spal. 25
279
2
spal. 25
407