Skip to content

Commit

Permalink
[IMP] change action_register_payment
Browse files Browse the repository at this point in the history
  • Loading branch information
maq-adhoc committed Jan 16, 2024
1 parent af4b903 commit e67b7e5
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
40 changes: 39 additions & 1 deletion account_payment_pro/models/account_move_line.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from odoo import models, fields, api
from odoo import models, fields, api, _
from odoo.exceptions import UserError


class AccountMoveLine(models.Model):
Expand All @@ -25,3 +26,40 @@ def _compute_payment_matched_amount(self):
debit_move_amount = sum(payment_lines.mapped('matched_debit_ids').filtered(lambda x: x.debit_move_id == rec).mapped('amount'))
credit_move_amount = sum(payment_lines.mapped('matched_credit_ids').filtered(lambda x: x.credit_move_id == rec).mapped('amount'))
rec.payment_matched_amount = debit_move_amount - credit_move_amount

def action_register_payment(self):

if self._use_default_payment_register():
return super().action_register_payment()

to_pay_move_lines = self.filtered(
lambda r: not r.reconciled and r.account_id.account_type in ['asset_receivable', 'liability_payable'])
if not to_pay_move_lines:
raise UserError(_('Nothing to be paid on selected entries'))
to_pay_partners = self.mapped('move_id.commercial_partner_id')
if len(to_pay_partners) > 1:
raise UserError(_('Selected recrods must be of the same partner'))

return {
'name': _('Register Payment'),
'res_model': 'account.payment',
'view_mode': 'form',
'views': [[False, 'form']],
'context': {
'active_model': 'account.move.line',
'active_ids': self.ids,
'default_partner_type': 'customer' if to_pay_move_lines[0].account_id.account_type == 'asset_receivable' else 'supplier',
'default_partner_id': to_pay_partners.id,
'default_to_pay_move_line_ids': to_pay_move_lines.ids,
# We set this because if became from other view and in the context has 'create=False'
# you can't crate payment lines (for ej: subscription)
'create': True,
'default_company_id': self.company_id.id,
'pop_up': True,
},
'target': 'current',
'type': 'ir.actions.act_window',
}

def _use_default_payment_register(self):
return False
2 changes: 1 addition & 1 deletion account_payment_pro/views/account_payment_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,4 @@
</field>
</record> -->

</odoo>
</odoo>

0 comments on commit e67b7e5

Please sign in to comment.