Skip to content

Commit

Permalink
[FIX] l10n_ar_ux: monkey patch post_load
Browse files Browse the repository at this point in the history
this way the monkey patch only is loaded if the module is installed.

closes #724

X-original-commit: ccf2b07
Signed-off-by: Juan José Scarafía <jjs@adhoc.com.ar>
  • Loading branch information
zaoral committed Sep 4, 2023
1 parent 7191955 commit 5ede4a0
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 34 deletions.
34 changes: 34 additions & 0 deletions l10n_ar_ux/__init__.py
Expand Up @@ -7,3 +7,37 @@
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


def monkey_patch_inverse_l10n_latam_document_number():
# monkey patch
orginal_method = AccountMove._inverse_l10n_latam_document_number

def _inverse_l10n_latam_document_number(self):
""" Parche feo para poder usar liquidaciones hasta que se mezcle https://github.com/odoo/odoo/pull/78632 en
master"""
orginal_method(self)
to_review = self.filtered(lambda x: (
x.journal_id.l10n_ar_is_pos
and x.l10n_latam_document_type_id
and x.l10n_latam_document_number
and (x.l10n_latam_manual_document_number or not x.highest_name)
))
for rec in to_review:
number = rec.l10n_latam_document_type_id._format_document_number(rec.l10n_latam_document_number)
current_pos = int(number.split("-")[0])
if current_pos != rec.journal_id.l10n_ar_afip_pos_number:
invoices = self.search([('journal_id', '=', rec.journal_id.id), ('posted_before', '=', True)], limit=1)
# If there is no posted before invoices the user can change the POS number (x.l10n_latam_document_number)
if (not invoices):
rec.journal_id.l10n_ar_afip_pos_number = current_pos
rec.journal_id._onchange_set_short_name()
# If not, avoid that the user change the POS number
else:
raise UserError(_('The document number can not be changed for this journal, you can only modify'
' the POS number if there is not posted (or posted before) invoices'))

AccountMove._inverse_l10n_latam_document_number = _inverse_l10n_latam_document_number
1 change: 1 addition & 0 deletions l10n_ar_ux/__manifest__.py
Expand Up @@ -46,4 +46,5 @@
'auto_install': True,
'application': False,
'post_init_hook': 'post_init_hook',
'post_load': 'monkey_patch_inverse_l10n_latam_document_number',
}
34 changes: 0 additions & 34 deletions l10n_ar_ux/models/account_move.py
Expand Up @@ -3,40 +3,6 @@
# directory
##############################################################################
from odoo import models, fields, api, _
from odoo.exceptions import ValidationError, UserError
from odoo.addons.l10n_ar.models.account_move import AccountMove
from odoo.addons.l10n_latam_invoice_document.models.account_move import AccountMove as AccountMoveOriginal
import re
import logging
_logger = logging.getLogger(__name__)


def _inverse_l10n_latam_document_number(self):
""" Parche feo para poder usar liquidaciones hasta que se mezcle https://github.com/odoo/odoo/pull/78632 en
master"""
AccountMoveOriginal._inverse_l10n_latam_document_number(self)
to_review = self.filtered(lambda x: (
x.journal_id.l10n_ar_is_pos
and x.l10n_latam_document_type_id
and x.l10n_latam_document_number
and (x.l10n_latam_manual_document_number or not x.highest_name)
))
for rec in to_review:
number = rec.l10n_latam_document_type_id._format_document_number(rec.l10n_latam_document_number)
current_pos = int(number.split("-")[0])
if current_pos != rec.journal_id.l10n_ar_afip_pos_number:
invoices = self.search([('journal_id', '=', rec.journal_id.id), ('posted_before', '=', True)], limit=1)
# If there is no posted before invoices the user can change the POS number (x.l10n_latam_document_number)
if (not invoices):
rec.journal_id.l10n_ar_afip_pos_number = current_pos
rec.journal_id._onchange_set_short_name()
# If not, avoid that the user change the POS number
else:
raise UserError(_('The document number can not be changed for this journal, you can only modify'
' the POS number if there is not posted (or posted before) invoices'))


AccountMove._inverse_l10n_latam_document_number = _inverse_l10n_latam_document_number


class AccountMove(models.Model):
Expand Down

0 comments on commit 5ede4a0

Please sign in to comment.