Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
2 ตอบกลับ
1615 มุมมอง

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
302
2
ก.ค. 25
707
1
มิ.ย. 25
737
3
มิ.ย. 25
1756
0
เม.ย. 25
1283