feat: extend journal code size to 15 and add automated fallback generation for system-created journals

This commit is contained in:
Suherdy Yacob 2026-05-11 11:28:09 +07:00
parent 92e73114b8
commit bff244d7e5

View File

@ -3,11 +3,21 @@ from odoo import fields, models
class AccountJournal(models.Model): class AccountJournal(models.Model):
_inherit = "account.journal" _inherit = "account.journal"
code = fields.Char( code = fields.Char(string="Short Code", size=15)
string="Short Code",
size=15, # ubah dari 5 → 15 @api.model_create_multi
compute="_compute_code", readonly=False, store=True, def create(self, vals_list):
required=True, precompute=True, for vals in vals_list:
help="Shorter name used for display. " # Safety fallback for journals created without code/type (e.g. system-generated like Tax Return)
"The journal entries of this journal will also be named using this prefix by default." 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)