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)