Skip to content

Commit

Permalink
[IMP] Block confirm payment
Browse files Browse the repository at this point in the history
  • Loading branch information
maq-adhoc committed Apr 29, 2024
1 parent e0ff2fa commit 887e29e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
18 changes: 17 additions & 1 deletion account_payment_pro/models/account_payment.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from odoo import models, fields, api, Command, _
from odoo.exceptions import ValidationError
from odoo.exceptions import ValidationError, UserError


class AccountPayment(models.Model):
Expand Down Expand Up @@ -148,6 +148,22 @@ def action_confirm(self):
self._check_to_pay_lines_account()
self.filtered(lambda x: x.state == 'draft').is_confirmed = True

def action_unconfirm(self):
# chequeamos lineas a pagar antes de confirmar pago para evitar idas y vueltas de validacion
self._check_to_pay_lines_account()
self.filtered(lambda x: x.state == 'draft').is_confirmed = False

@api.model
def _get_confimed_blocked_field(self):
return ['partner_id', 'partner_type', 'to_pay_move_line_ids', 'unreconciled_amount',
'withholdable_advanced_amount', 'company_id', 'to_pay_amount', 'amount']

def write(self, vals):
if not self.user_has_groups('account_payment_pro.account_confirm_payment') and self.filtered('is_confirmed'):
if set(vals) & set(self._get_confimed_blocked_field()):
raise UserError(_('You cannot modify an approved payment. You must back to edit it.'))
return super().write(vals)

@api.depends('company_id.double_validation', 'partner_type')
def _compute_requiere_double_validation(self):
double_validation = self.env['account.payment']
Expand Down
2 changes: 2 additions & 0 deletions account_payment_pro/views/account_payment_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
</button>
<button name="action_post" position="before">
<button name="action_confirm" class="oe_highlight" string="Approve" groups="account_payment_pro.account_confirm_payment" invisible="state != 'draft' or not requiere_double_validation" type="object"/>
<button name="action_unconfirm" string="Back to Edit" invisible="state == 'draft' and not is_confirmed" type="object"/>

</button>
<!-- seccion para mejora pagos en otra moneda -->
<div name="amount_div" position="after">
Expand Down

0 comments on commit 887e29e

Please sign in to comment.