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):
_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)