67 lines
3.4 KiB
Python
67 lines
3.4 KiB
Python
# -*- coding: utf-8 -*-
|
|
from odoo.addons.account.models.chart_template import template
|
|
from odoo import models, modules
|
|
|
|
|
|
class AccountChartTemplate(models.AbstractModel):
|
|
_inherit = 'account.chart.template'
|
|
|
|
def _get_account_accountant_res_company(self, chart_template):
|
|
# Called when installing the Accountant module
|
|
company = self.env.company
|
|
data = self._get_chart_template_data(chart_template)
|
|
company_data = data['res.company'].get(company.id, {})
|
|
|
|
# Pre-reload to ensure the necessary xmlids for the load exist in case they were deleted or not created yet.
|
|
required_data = {k: v for k, v in data.items() if k in ['account.journal', 'account.account']}
|
|
self._pre_reload_data(company, data['template_data'], required_data)
|
|
|
|
return {
|
|
company.id: {
|
|
'deferred_expense_journal_id': company.deferred_expense_journal_id.id or company_data.get('deferred_expense_journal_id'),
|
|
'deferred_revenue_journal_id': company.deferred_revenue_journal_id.id or company_data.get('deferred_revenue_journal_id'),
|
|
'deferred_expense_account_id': company.deferred_expense_account_id.id or company_data.get('deferred_expense_account_id'),
|
|
'deferred_revenue_account_id': company.deferred_revenue_account_id.id or company_data.get('deferred_revenue_account_id'),
|
|
}
|
|
}
|
|
|
|
def _get_chart_template_data(self, chart_template):
|
|
# OVERRIDE chart template to process the default values for deferred journal and accounts.
|
|
|
|
data = super()._get_chart_template_data(chart_template)
|
|
|
|
for company_data in data['res.company'].values():
|
|
company_data['deferred_expense_journal_id'] = (
|
|
company_data.get('deferred_expense_journal_id')
|
|
or next((xid for xid, d in data['account.journal'].items() if d['type'] == 'general'), None)
|
|
)
|
|
|
|
company_data['deferred_revenue_journal_id'] = (
|
|
company_data.get('deferred_revenue_journal_id')
|
|
or next((xid for xid, d in data['account.journal'].items() if d['type'] == 'general'), None)
|
|
)
|
|
|
|
company_data['deferred_expense_account_id'] = (
|
|
company_data.get('deferred_expense_account_id')
|
|
or next((xid for xid, d in data['account.account'].items() if d['account_type'] == 'asset_current'), None)
|
|
)
|
|
|
|
company_data['deferred_revenue_account_id'] = (
|
|
company_data.get('deferred_revenue_account_id')
|
|
or next((xid for xid, d in data['account.account'].items() if d['account_type'] == 'liability_current'), None)
|
|
)
|
|
|
|
return data
|
|
|
|
def _post_load_data(self, template_code, company, template_data):
|
|
super()._post_load_data(template_code, company, template_data)
|
|
|
|
sepa_countries = self.env.ref('base.sepa_zone').country_ids
|
|
if company.country_id in sepa_countries:
|
|
sepa_module = self.env['ir.module.module'].sudo().search([('name', '=', 'account_iso20022')], limit=1)
|
|
if sepa_module and sepa_module.state != 'installed':
|
|
if self.env.registry.ready and not self.env.registry._init and not modules.module.current_test and not self.env.context.get('install_demo'):
|
|
sepa_module.button_immediate_install()
|
|
else:
|
|
sepa_module.button_install()
|