跳至内容
菜单
此问题已终结
2 回复
243 查看

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.

形象
丢弃
最佳答案

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

形象
丢弃
最佳答案

The Odoo 18.0 constraint on account codes, preventing hyphens, is due to the new account report engine's requirements for alphanumeric characters and dots only. This ensures compatibility and avoids issues during report generation.



  Consider alternative account code structures that comply with Odoo's constraint. For example, use 100001, 210022, or similar.

  If you require hyphens for organizational reasons, explore custom development options to modify the validation rule. This would involve altering the _check_account_code method to accept hyphens, but it requires careful consideration of potential downstream effects on reporting.

  Thoroughly test any custom modifications in a development environment before deploying them to production to avoid data inconsistencies or report errors.


For personalized assistance:
https://www.pragtech.co.in/contact.html

形象
丢弃
相关帖文 回复 查看 活动
2
9月 25
984
0
9月 25
57
1
9月 25
624
0
9月 25
29
1
9月 25
102