I want to automatically install the fiscal localization package to generic chart template, I wrote a code, but that is not working well as It is not installing the journals that we get when we install generic chart template manually,
I'm using model res.config.settings and field chart_template
This is my code
def _install_generic_chart_template(self,company):
try:
# Check if the company already has a chart of accounts installed
if not company.chart_template: # Assuming 'chart_template' is the name of your selection field
# Log available chart templates
available_chart_templates = self.env['res.config.settings'].search([('chart_template', '!=', False)])
_logger.info(f"Available Chart Templates: {available_chart_templates.mapped('chart_template')}")
# Find and install a generic chart of accounts template
chart_template = available_chart_templates and available_chart_templates[0].chart_template
if chart_template:
# Set the chart template for the new company
company.write({'chart_template': chart_template})
# Update res.config.settings with the selected chart template
config_settings = self.env['res.config.settings'].sudo().create({
'company_id': company.id,
'chart_template': chart_template,
})
config_settings.execute()
_logger.info(
f"Updated res.config.settings for company {company.name} with chart template: {chart_template}")
except Exception as e:
_logger.exception(f"Error installing generic chart of accounts for company {company.name}")
So anyone can help me with that?
The issue is that, I get message in logger that, Updates res.config.settings, but the default behavior that it installs the journals along with it is not being done.