Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
2 Відповіді
1611 Переглядів

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.

Найкраща відповідь

Hello,


I'm currently using this in one of my projects, it works like a charm:

env["account.chart.template"].try_loading(template_code, company)

I'm simply using one of the following template_code depending on the company:

  • ch
  • fr
  • generic_coa

BR,

Nico

Аватар
Відмінити
Найкраща відповідь

In your code, you’re creating a new res.config.settings record for each company and then calling the execute method. This method is responsible for installing the chart template, so if it’s not working as expected, the problem could be here.

You might want to debug this part of your code to see what’s happening. Check if the execute method is being called and if it’s running without errors. Also, verify that the correct chart template is being set on the company and the res.config.settings record.


Аватар
Відмінити
Related Posts Відповіді Переглядів Дія
0
серп. 25
298
2
лип. 25
705
1
черв. 25
737
3
черв. 25
1749
0
квіт. 25
1282