Skip to content

Commit

Permalink
[IMP] l10n_ar_edi_ux: agregar funcionalidad de debitar cheques propios.
Browse files Browse the repository at this point in the history
Tarea: 34995
Lo hacemos acá y no en l10n_ar_ux porque no tenemos enterprise y usamos acá un metodo de account_accountant.
  • Loading branch information
pablohmontenegro committed Dec 19, 2023
1 parent 391993c commit 0d41392
Show file tree
Hide file tree
Showing 9 changed files with 116 additions and 3 deletions.
1 change: 1 addition & 0 deletions l10n_ar_edi_ux/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Argentinian Electronic Invoicing UX
* Implement electronic validation of documents created as purchase documents (for eg. liquido producto). There is an open PR to include this in Odoo standard
* Disable l10n_ar_ux view that add Argentinian Localization accounting settings and use the one added by l10n_ar_edi
* Logic to connecto to AFIP Padron using connection approach in enterprise module l10n_ar_edi
* Debit checks from payments. This functionality is included here because we use methods from enterprise (account_accountant).

About Padron:

Expand Down
6 changes: 4 additions & 2 deletions l10n_ar_edi_ux/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
'name': 'Argentinian Electronic Invoicing UX',
'version': "16.0.1.2.0",
'version': "16.0.1.3.0",
'category': 'Localization/Argentina',
'sequence': 14,
'author': 'ADHOC SA',
Expand All @@ -17,11 +17,13 @@
'data': [
'wizards/res_config_settings_view.xml',
'wizards/res_partner_update_from_padron_wizard_view.xml',
'wizards/account_payment_group_invoice_wizard_view.xml',
'wizards/account_check_action_wizard_view.xml',
'views/res_partner_view.xml',
'views/account_move_view.xml',
'views/account_journal_view.xml',
'views/l10n_ar_boarding_permission_view.xml',
'views/account_payment_view.xml',
'wizards/account_payment_group_invoice_wizard_view.xml',
'security/ir.model.access.csv',
],
'demo': [
Expand Down
7 changes: 6 additions & 1 deletion l10n_ar_edi_ux/models/account_journal.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from odoo import models, _
from odoo import models, fields, _
from odoo.exceptions import UserError
from odoo.tools import format_date
import datetime
Expand All @@ -7,6 +7,11 @@
class AccountJournal(models.Model):
_inherit = "account.journal"

check_add_debit_button = fields.Boolean(
string="Agregar botón de débito",
help="Si marca esta opción podrá debitar los cheques con un botón desde los mismo.")
check_debit_journal_id = fields.Many2one('account.journal', domain="[('company_id', '=', company_id), ('type', '=', 'general')]", help="Debe seleccionar un diario de tipo 'Varios' donde se realizará el asiento del débito")

def l10n_ar_check_afip_doc_types(self):
""" This method shows the valid document types for each Webservice. """
self.ensure_one()
Expand Down
1 change: 1 addition & 0 deletions l10n_ar_edi_ux/security/ir.model.access.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ access_res_partner_update_from_padron_field,access_res_partner_update_from_padro
access_res_partner_update_from_padron_wizard,access_res_partner_update_from_padron_wizard,model_res_partner_update_from_padron_wizard,base.group_user,1,1,1,0
access_res_partner_update_from_padron_info,access_res_partner_update_from_padron_info,model_res_partner_update_from_padron_info,base.group_user,1,1,1,1
access_l10n_ar_boarding_permission,access_l10n_ar_boarding_permission,model_l10n_ar_boarding_permission,base.group_user,1,1,1,1
access_account_check_action_wizard,access_account_check_action_wizard,model_account_check_action_wizard,base.group_user,1,1,1,1
12 changes: 12 additions & 0 deletions l10n_ar_edi_ux/views/account_journal_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,16 @@
</button>
</field>
</record>

<record id="view_account_journal_tree" model="ir.ui.view">
<field name="name">account.journal.tree</field>
<field name="model">account.journal</field>
<field name="inherit_id" ref="l10n_latam_check.view_account_journal_tree"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='l10n_latam_manual_checks']" position="after">
<field name="check_add_debit_button" attrs="{'invisible': [('l10n_latam_manual_checks', '=', False)]}"/>
<field name="check_debit_journal_id" attrs="{'invisible': [('check_add_debit_button', '=', False)], 'required':[('check_add_debit_button','=',True)]}"/>
</xpath>
</field>
</record>
</odoo>
14 changes: 14 additions & 0 deletions l10n_ar_edi_ux/views/account_payment_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<odoo>

<record id="view_account_payment_form_inherited" model="ir.ui.view">
<field name="name">account.payment.form.inherited</field>
<field name="model">account.payment</field>
<field name="inherit_id" ref="account.view_account_payment_form" />
<field name="arch" type="xml">
<xpath expr="//button[@name='action_post']" position="after">
<button name="%(action_debit_check_wizard)d" string="Debit check" type="action" attrs="{'invisible': ['|', '|', '|',('payment_method_code', '!=', 'check_printing'), ('state', '!=', 'posted'), ('is_move_sent', '=', False), ('is_matched', '=', True)]}"/>
</xpath>
</field>
</record>

</odoo>
1 change: 1 addition & 0 deletions l10n_ar_edi_ux/wizards/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
from . import res_partner_update_from_padron_wizard
from . import res_config_settings
from . import account_payment_group_invoice_wizard
from . import account_check_action_wizard
49 changes: 49 additions & 0 deletions l10n_ar_edi_ux/wizards/account_check_action_wizard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
##############################################################################
# For copyright and license notices, see __manifest__.py file in module root
# directory
##############################################################################
from odoo import fields, models, _
from odoo.exceptions import ValidationError


class AccountCheckActionWizard(models.TransientModel):
_name = 'account.check.action.wizard'
_description = 'Account Check Action Wizard'

date = fields.Date(
default=fields.Date.context_today,
required=True,
)

def action_confirm(self):
""" Este método sirve para hacer el débito de cheques con cuenta outstanding desde los payments con método de pago de cheques. """
payment = self.env['account.payment'].browse(self._context.get('active_id', False))
if self.date < payment.date:
raise ValidationError(f'La fecha del débito del cheque {self.date} no puede ser inferior a la fecha de emisión del mismo {payment.date}.')
# Línea del cheque a conciliar.
move_line_ids = [payment.line_ids.filtered(lambda x: not x.reconciled).id]
# Obtenemos la cuenta outstanding del método de pago pentientes "manual" del diario del pago o bien la "Cuenta de pagos pentientes" de la compañía.
outstanding_account = self._get_outstanding_account(payment)
# Obtenemos fecha, importe, pasamos cuenta outstanding y el diario es de tipo varios que está vinculado al diario del pago del cheque (ver campo Check Debit Journal en el diario) para que nos permita hacer la conciliación. Lo utilizamos como un diario "puente".
new_mv_line_dicts = [{'name': f'Débito cheque nro {payment.check_number}',
'balance': abs(payment.line_ids.filtered(lambda x: not x.reconciled).balance),
'account_id': outstanding_account.id,
'journal_id': payment.journal_id.check_debit_journal_id.id,
'date': self.date,
}]
self.env['account.reconciliation.widget']._process_move_lines(move_line_ids, new_mv_line_dicts)
payment.message_post(body=f'El cheque nro "{payment.check_number}" ha sido debitado.')

def _get_outstanding_account(self, payment):
""" Obtenemos la cuenta outstanding para hacer el débito de cheques y hacemos las validaciones correspondientes. """
journal = payment.journal_id
journal_manual_payment_method = journal.outbound_payment_method_line_ids.filtered(lambda x: x.code=='manual')
company_outstanding_payment_account = journal.company_id.account_journal_payment_credit_account_id
outstanding_account = journal_manual_payment_method.payment_account_id or company_outstanding_payment_account
if not outstanding_account:
raise ValidationError(f'No existe método de pago manual en el diario {journal.display_name} ni "Cuenta de pagos pendientes" establecida para la compañìa {journal.company_id.display_name}.')
if journal_manual_payment_method.payment_account_id and not journal_manual_payment_method.payment_account_id.reconcile:
raise ValidationError(f'La "Cuenta de pagos pendientes" del método de pago pentientes "Manual" del diario {journal.display_name} no permite realizar conciliación. Usar cuenta "outstanding".')
if company_outstanding_payment_account and not company_outstanding_payment_account.reconcile:
raise ValidationError(f'La cuenta "Cuenta de pagos pendientes" de la compañía {journal.company_id.display_name} no permite realizar conciliación. Usar cuenta "outstanding".')
return outstanding_account
28 changes: 28 additions & 0 deletions l10n_ar_edi_ux/wizards/account_check_action_wizard_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>

<record model="ir.ui.view" id="account_check_action_wizard_form_view">
<field name="name">account.check.action.wizard.form</field>
<field name="model">account.check.action.wizard</field>
<field name="arch" type="xml">
<form string="Check Action">
<group >
<field name="date"/>
</group>
<footer>
<button string="Confirm" name="action_confirm" type="object" class="oe_highlight"/>
or
<button string="Cancel" class="oe_link" special="cancel"/>
</footer>
</form>
</field>
</record>

<record id="action_debit_check_wizard" model="ir.actions.act_window">
<field name="name">Check Action</field>
<field name="res_model">account.check.action.wizard</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>

</odoo>

0 comments on commit 0d41392

Please sign in to comment.