From b5af7fd621ea4056f16899704cb20d575ec7d13b Mon Sep 17 00:00:00 2001 From: Katherine Zaoral Date: Mon, 28 Aug 2023 16:25:02 -0300 Subject: [PATCH] [FIX] l10n_ar_ux: monkey patch post_load this way the monkey patch only is loaded if the module is installed. --- l10n_ar_ux/__init__.py | 34 +++++++++++++++++++++++++++++++ l10n_ar_ux/__manifest__.py | 1 + l10n_ar_ux/models/account_move.py | 34 ------------------------------- 3 files changed, 35 insertions(+), 34 deletions(-) diff --git a/l10n_ar_ux/__init__.py b/l10n_ar_ux/__init__.py index bf4a836c4..bbed101e2 100644 --- a/l10n_ar_ux/__init__.py +++ b/l10n_ar_ux/__init__.py @@ -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 diff --git a/l10n_ar_ux/__manifest__.py b/l10n_ar_ux/__manifest__.py index f09ebba90..62664c43d 100644 --- a/l10n_ar_ux/__manifest__.py +++ b/l10n_ar_ux/__manifest__.py @@ -48,4 +48,5 @@ 'auto_install': True, 'application': False, 'post_init_hook': 'post_init_hook', + 'post_load': 'monkey_patch_inverse_l10n_latam_document_number', } diff --git a/l10n_ar_ux/models/account_move.py b/l10n_ar_ux/models/account_move.py index e0a494f27..cee403c74 100644 --- a/l10n_ar_ux/models/account_move.py +++ b/l10n_ar_ux/models/account_move.py @@ -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):