[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 <jco@odoo.com>
This commit is contained in:
Pablo Montenegro
2024-01-30 21:08:05 +00:00
parent 9c4fd4fe8b
commit 08e49fe88e
@@ -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