24 lines
973 B
Python
Executable File
24 lines
973 B
Python
Executable File
from odoo import api, fields, models
|
|
|
|
class AccountJournal(models.Model):
|
|
_inherit = "account.journal"
|
|
|
|
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)
|