From bff244d7e57e2e7a0d37fe780b73b5aa59ec3659 Mon Sep 17 00:00:00 2001 From: Suherdy Yacob Date: Mon, 11 May 2026 11:28:09 +0700 Subject: [PATCH] feat: extend journal code size to 15 and add automated fallback generation for system-created journals --- models/account_journal.py | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/models/account_journal.py b/models/account_journal.py index e76c3ee..99afaff 100755 --- a/models/account_journal.py +++ b/models/account_journal.py @@ -3,11 +3,21 @@ from odoo import fields, models class AccountJournal(models.Model): _inherit = "account.journal" - code = fields.Char( - string="Short Code", - size=15, # ubah dari 5 → 15 - compute="_compute_code", readonly=False, store=True, - required=True, precompute=True, - help="Shorter name used for display. " - "The journal entries of this journal will also be named using this prefix by default." - ) + code = fields.Char(string="Short Code", size=15) + + @api.model_create_multi + def create(self, vals_list): + for vals in vals_list: + # Safety fallback for journals created without code/type (e.g. system-generated like Tax Return) + if not vals.get('code') and not vals.get('type'): + name = vals.get('name', '') + if isinstance(name, dict): + name = name.get('en_US', '') or name.get('id_ID', '') or str(name) + + if 'Tax Return' in str(name): + vals['type'] = 'general' + vals['code'] = 'TAX' + else: + # Generic fallback to avoid DB constraint crash for other automated journals + vals['code'] = 'TEMP' + return super().create(vals_list)