[FIX] account: multi-company CoA installation
With the changes in the ORM, the method _compute_has_chart_of_accounts is now also called after the create, erasing the value of chart_template_id. We cannot set that field as related to the company because set_values checks if the value changes and it wouldnt be the case if we already changed it at the validation of the config form. So this commit checks if there is already a value before setting the default. closes odoo/odoo#36780 Signed-off-by: Quentin De Paoli (qdp) <qdp@openerp.com>
This commit is contained in:
@@ -17,7 +17,7 @@ class ResConfigSettings(models.TransientModel):
|
||||
domain="[('company_id', '=', company_id), ('type', '=', 'general')]",
|
||||
help='The accounting journal where automatic exchange differences will be registered')
|
||||
has_chart_of_accounts = fields.Boolean(compute='_compute_has_chart_of_accounts', string='Company has a chart of accounts')
|
||||
chart_template_id = fields.Many2one('account.chart.template', string='Template',
|
||||
chart_template_id = fields.Many2one('account.chart.template', string='Template', default=lambda self: self.env.company.chart_template_id,
|
||||
domain="[('visible','=', True)]")
|
||||
sale_tax_id = fields.Many2one('account.tax', string="Default Sale Tax", related='company_id.account_sale_tax_id', readonly=False)
|
||||
purchase_tax_id = fields.Many2one('account.tax', string="Default Purchase Tax", related='company_id.account_purchase_tax_id', readonly=False)
|
||||
@@ -91,14 +91,13 @@ class ResConfigSettings(models.TransientModel):
|
||||
super(ResConfigSettings, self).set_values()
|
||||
if self.group_multi_currency:
|
||||
self.env.ref('base.group_user').write({'implied_ids': [(4, self.env.ref('product.group_sale_pricelist').id)]})
|
||||
""" install a chart of accounts for the given company (if required) """
|
||||
# install a chart of accounts for the given company (if required)
|
||||
if self.chart_template_id and self.chart_template_id != self.company_id.chart_template_id:
|
||||
self.chart_template_id._load(15.0, 15.0, self.env.company)
|
||||
|
||||
@api.depends('company_id')
|
||||
def _compute_has_chart_of_accounts(self):
|
||||
self.has_chart_of_accounts = bool(self.company_id.chart_template_id)
|
||||
self.chart_template_id = self.company_id.chart_template_id or False
|
||||
self.has_accounting_entries = self.env['account.chart.template'].existing_accounting(self.company_id)
|
||||
|
||||
@api.onchange('show_line_subtotals_tax_selection')
|
||||
|
||||
Reference in New Issue
Block a user