Skip to Content
Menu
This question has been flagged
1 Reply
2352 Views

How configure chart of account for company during company creation in programmatic way??

I have tried to pass a chart of account template id inside company creation as follow:

@api.model
def create(self, vals_list):
chart_tempalte = self.env['account.chart.template'].search([('name','=','U.A.E Chart of Accounts - Standard')])
if chart_tempalte:
vals_list['chart_template_id'] = chart_tempalte.id
result = super(ResCompany, self).create(vals_list)
return result

But the warning message to configure the chart of account still pop up while creating invoice.

Any solution ??? Thanks in advance !!!

Avatar
Discard
Best Answer

Hello Kabeer,

Please try this code,

@api.model
def create(self, vals_list):
    result = super(ResCompany, self).create(vals_list)
    chart_tempalte = self.env['account.chart.template'].search([('name','=','U.A.E Chart of Accounts - Standard')], limit=1)
    self.env.user.write({'company_id':result.id})
    chart_tempalte.try_loading_for_current_company()
    return result


Please add "U.A.E Chart of Accounts - Standard" module as depends in your module, or add code to find the module from 'ir.module.module' and fetch the template id and use it as 'chart_tempalte' in above code.


Hope it will help you,

thanks,


Avatar
Discard