From 08e49fe88ee7fbd3ab7bf2d472567f1e13a25ad9 Mon Sep 17 00:00:00 2001 From: Pablo Montenegro Date: Tue, 26 Dec 2023 14:18:34 -0300 Subject: [PATCH] [IMP] l10n_ar: fiscal position auto-detection Prior to this commit, fiscal positions auto-detecion was completely override for Argentinian countries. With this improvements the afip responsibility field can be combined as a filter to choose the proper fiscal position. Example of a new use case could be: * Name: Gross Income Perceptions Buenos Aires * Detect Automatically = True * Afip Resp. Type = Responsable Inscripto * Country = Argentina * Federal states = Buenos Aires So, this fiscal position will be automatically choosen only for responsables inscriptos of Buenos Aires. Previous use cases still work. closes odoo/odoo#150652 X-original-commit: 4c5987eb1ac7687eb0c6467d99fb3052e4843a07 Signed-off-by: Josse Colpaert --- .../l10n_ar/models/account_fiscal_position.py | 31 ++++--------------- 1 file changed, 6 insertions(+), 25 deletions(-) diff --git a/addons/l10n_ar/models/account_fiscal_position.py b/addons/l10n_ar/models/account_fiscal_position.py index 2726d59017e..d698a4544c0 100644 --- a/addons/l10n_ar/models/account_fiscal_position.py +++ b/addons/l10n_ar/models/account_fiscal_position.py @@ -13,31 +13,12 @@ class AccountFiscalPosition(models.Model): @api.model def _get_fiscal_position(self, partner, delivery=None): - """ Take into account the partner afip responsibility in order to auto-detect the fiscal position """ if self.env.company.country_id.code != "AR": return super()._get_fiscal_position(partner, delivery=delivery) + return super(AccountFiscalPosition, self.with_context(l10n_ar_afip_responsibility_type_id=partner.l10n_ar_afip_responsibility_type_id.id))._get_fiscal_position(partner, delivery=delivery) - # if no delivery use invoicing - if not delivery: - delivery = partner - - # partner manually set fiscal position always win - manual_fiscal_position = delivery.property_account_position_id or partner.property_account_position_id - if manual_fiscal_position: - return manual_fiscal_position - - domain = [ - ('auto_apply', '=', True), - ('l10n_ar_afip_responsibility_type_ids', '=', partner.l10n_ar_afip_responsibility_type_id.id), - ('company_id', '=', self.env.company.id), - ] - return self.sudo().search(domain, limit=1) - - @api.onchange('l10n_ar_afip_responsibility_type_ids', 'country_group_id', 'country_id', 'zip_from', 'zip_to') - def _onchange_afip_responsibility(self): - if self.company_id.account_fiscal_country_id.code == "AR": - if self.l10n_ar_afip_responsibility_type_ids and any(['country_group_id', 'country_id', 'zip_from', 'zip_to']): - return {'warning': { - 'title': _("Warning"), - 'message': _('If use AFIP Responsibility then the country / zip codes will be not take into account'), - }} + def _prepare_fpos_base_domain(self, vat_required): + domain = super()._prepare_fpos_base_domain(vat_required) + if self._context.get('l10n_ar_afip_responsibility_type_id'): + domain += [('l10n_ar_afip_responsibility_type_ids', '=', self._context.get('l10n_ar_afip_responsibility_type_id'))] + return domain