Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP] l10n_ar_edi_ux: agregar funcionalidad de debitar cheques propios.
Tarea: 34995 Lo hacemos acá y no en l10n_ar_ux porque no tenemos enterprise y usamos acá un metodo de account_accountant. closes #300 X-original-commit: 9454c75 Signed-off-by: Juan José Scarafía <jjs@adhoc.com.ar> Signed-off-by: pablohmontenegro <pam@adhoc.com.ar>
- Loading branch information
1 parent
d14c11a
commit 03cb5e2
Showing
11 changed files
with
136 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from odoo import fields, models | ||
|
||
|
||
class AccountPayment(models.Model): | ||
_inherit = 'account.payment' | ||
|
||
# Diario 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 el débito del cheque. | ||
# Lo utilizamos como un diario "puente". Si no está establecido entonces usamos este campo para hacer invisible el botón para debitar cheques en la vista form del payment (es decir, del cheque). | ||
check_debit_journal_id = fields.Many2one(related='journal_id.check_debit_journal_id', readonly=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<odoo> | ||
<!-- Heredamos la vista de account payment para agregar el botón para debitar cheques propios. --> | ||
<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"> | ||
<field name='check_debit_journal_id' invisible="1"/> | ||
<button name="%(action_debit_check_wizard)d" string="Debit check" type="action" invisible="payment_method_code != 'check_printing' or state != 'posted' or not is_move_sent or is_matched or not check_debit_journal_id"/> | ||
</xpath> | ||
</field> | ||
</record> | ||
|
||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
############################################################################## | ||
# For copyright and license notices, see __manifest__.py file in module root | ||
# directory | ||
############################################################################## | ||
from odoo import fields, models | ||
from odoo.exceptions import ValidationError, UserError | ||
|
||
|
||
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. | ||
liquidity_lines, counterpart_lines, writeoff_lines = payment._seek_for_lines() | ||
move_line_ids = liquidity_lines.ids | ||
# 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 = {'label': f'Débito cheque nro {payment.check_number}', | ||
'amount': abs(sum(liquidity_lines.mapped('balance'))), | ||
'account_id': outstanding_account.id, | ||
'journal_id': payment.journal_id.check_debit_journal_id.id, | ||
'date': self.date, | ||
'move_line_ids': move_line_ids | ||
} | ||
# Aquí hacemos el asiento del débito. | ||
wizard = self.env['account.reconcile.wizard'].with_context(active_model='account.move.line').new({}) | ||
for index, value in new_mv_line_dicts.items(): | ||
wizard[index] = value | ||
wizard.reconcile() | ||
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') | ||
outstanding_account = (journal_manual_payment_method.payment_account_id or journal.company_id.account_journal_payment_credit_account_id) | ||
if not outstanding_account: | ||
raise UserError("No es posible crear un nuevo débito de cheque sin una cuenta outstanding de pagos establecida ya sea en la compañía o en el método de pagos 'manual' en el diario %s." % (payment.journal_id.display_name)) | ||
return outstanding_account |
29 changes: 29 additions & 0 deletions
29
l10n_ar_edi_ux/wizards/account_check_action_wizard_view.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<odoo> | ||
|
||
<!-- Este wizard solo sirve para determinar en que fecha se va a debitar el cheque propio correspondiente desde la vista form del payment. --> | ||
<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> |