diff --git a/addons/account/models/account_tax.py b/addons/account/models/account_tax.py index 70862427cb3..e9478ceb022 100644 --- a/addons/account/models/account_tax.py +++ b/addons/account/models/account_tax.py @@ -27,12 +27,30 @@ class AccountTaxGroup(models.Model): property_advance_tax_payment_account_id = fields.Many2one('account.account', company_dependent=True, string='Advance Tax payment account') country_id = fields.Many2one(string="Country", comodel_name='res.country', help="The country for which this tax group is applicable.") - def _any_is_configured(self, company_id): - domain = expression.OR([[('property_tax_payable_account_id', '!=', False)], - [('property_tax_receivable_account_id', '!=', False)], - [('property_advance_tax_payment_account_id', '!=', False)]]) - group_with_config = self.with_company(company_id).search_count(domain) - return group_with_config > 0 + @api.model + def _check_misconfigured_tax_groups(self, company, countries): + """ Searches the tax groups used on the taxes from company in countries that don't have + at least a tax payable account, a tax receivable account or an advance tax payment account. + + :return: A boolean telling whether or not there are misconfigured groups for any + of these countries, in this company + """ + + # This cannot be refactored to check for misconfigured groups instead + # because of an ORM limitation with search on property fields: + # searching on property = False also returns the properties using the default value, + # even if it's non-empty. + # (introduced here https://github.com/odoo/odoo/pull/6044) + all_configured_groups_ids = self.with_company(company)._search([ + ('property_tax_payable_account_id', '!=', False), + ('property_tax_receivable_account_id', '!=', False), + ]) + + return bool(self.env['account.tax'].search([ + ('company_id', '=', company.id), + ('tax_group_id', 'not in', all_configured_groups_ids), + ('country_id', 'in', countries.ids), + ], limit=1)) class AccountTax(models.Model):