Skip to content

Commit

Permalink
[FIX] l10n_ar_ux: monkey patch fiscal_position post_load
Browse files Browse the repository at this point in the history
Task: 34656
  • Loading branch information
mem-adhoc committed Nov 13, 2023
1 parent 4309d8c commit 5269a31
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 44 deletions.
43 changes: 43 additions & 0 deletions l10n_ar_ux/__init__.py
Expand Up @@ -4,13 +4,15 @@
##############################################################################
from . import controllers
from . import models
from odoo import api
from . import reports
from . import wizards
from .hooks import post_init_hook

from odoo.addons.l10n_latam_invoice_document.models.account_move import AccountMove
from odoo.exceptions import UserError

from odoo.addons.l10n_ar.models.account_fiscal_position import AccountFiscalPosition

def monkey_patch_inverse_l10n_latam_document_number():
# monkey patch
Expand Down Expand Up @@ -41,3 +43,44 @@ def _inverse_l10n_latam_document_number(self):
' the POS number if there is not posted (or posted before) invoices'))

AccountMove._inverse_l10n_latam_document_number = _inverse_l10n_latam_document_number

def monkey_patch_inverse__get_fiscal_position():

@api.model
def _get_fiscal_position(self, partner, delivery=None):
company = self.env.company
if company.country_id.code == "AR":
self = self.with_context(
company_code='AR',
l10n_ar_afip_responsibility_type_id=partner.l10n_ar_afip_responsibility_type_id.id)
return super(AccountFiscalPosition, self)._get_fiscal_position(partner, delivery=delivery)


AccountFiscalPosition._get_fiscal_position = _get_fiscal_position


class AccountFiscalPositionMp(models.Model):

_inherit = 'account.fiscal.position'

@api.model
def _search(self, args, offset=0, limit=None, order=None, count=False, access_rights_uid=None):
""" Take into account the partner afip responsibility in order to auto-detect the fiscal position """
if self._context.get('company_code') == 'AR':
args += [('l10n_ar_afip_responsibility_type_ids', '=', self._context.get('l10n_ar_afip_responsibility_type_id'))]
return super()._search(args, offset, limit, order, count=count, access_rights_uid=access_rights_uid)

def _onchange_afip_responsibility(self):
return {}

@api.model
def _get_fpos_by_region(self, country_id=False, state_id=False, zipcode=False, vat_required=False):
if country_id and 'website_id' in self._context and 'l10n_ar_afip_responsibility_type_id' not in self._context:
company = self.env['res.company'].browse(self._context.get('force_company', self.env.company.id))
if company.country_id.code == 'AR':
self = self.with_context(company_code='AR')
# odoo only match fiscal positions if partner has a country, we've many customers with partners with country_id = False
# so, for ARG, if no country is configured we use Argentina for the fiscal autodetection
if not country_id and 'l10n_ar_afip_responsibility_type_id' in self._context:
country_id = self.env.ref('base.ar').id
return super()._get_fpos_by_region(country_id=country_id, state_id=state_id, zipcode=zipcode, vat_required=vat_required)
1 change: 1 addition & 0 deletions l10n_ar_ux/__manifest__.py
Expand Up @@ -47,4 +47,5 @@
'application': False,
'post_init_hook': 'post_init_hook',
'post_load': 'monkey_patch_inverse_l10n_latam_document_number',
'post_load': 'monkey_patch_inverse__get_fiscal_position',
}
1 change: 0 additions & 1 deletion l10n_ar_ux/models/__init__.py
Expand Up @@ -16,4 +16,3 @@
from . import res_config_settings
from . import ir_actions_report
from . import account_journal
from . import account_fiscal_position
43 changes: 0 additions & 43 deletions l10n_ar_ux/models/account_fiscal_position.py

This file was deleted.

0 comments on commit 5269a31

Please sign in to comment.