mirror of
https://github.com/NaN-tic/trytond-account_payment_gateway_invoice.git
synced 2023-12-14 03:32:54 +01:00
Implements confirm method of gateway transaction
This commit is contained in:
parent
0cc03d3739
commit
3784189d86
2 changed files with 55 additions and 1 deletions
51
gateway.py
51
gateway.py
|
@ -1,7 +1,10 @@
|
|||
# This file is part account_payment_gateway_invoice module for Tryton.
|
||||
# The COPYRIGHT file at the top level of this repository contains
|
||||
# the full copyright notices and license terms.
|
||||
from trytond.pool import PoolMeta
|
||||
from trytond.pool import Pool, PoolMeta
|
||||
|
||||
from trytond.transaction import Transaction
|
||||
|
||||
|
||||
__all__ = ['AccountPaymentGatewayTransaction']
|
||||
__metaclass__ = PoolMeta
|
||||
|
@ -15,3 +18,49 @@ class AccountPaymentGatewayTransaction:
|
|||
res = super(AccountPaymentGatewayTransaction, cls)._get_origin()
|
||||
res.append('account.invoice')
|
||||
return res
|
||||
|
||||
@classmethod
|
||||
def confirm(cls, transactions):
|
||||
pool = Pool()
|
||||
Invoice = pool.get('account.invoice')
|
||||
PayInvoice = pool.get('account.invoice.pay', type='wizard')
|
||||
|
||||
to_update = []
|
||||
for transaction in transactions:
|
||||
if isinstance(transaction.origin, Invoice):
|
||||
invoice = transaction.origin
|
||||
Invoice.workflow_to_posted([invoice])
|
||||
if not invoice.amount_to_pay:
|
||||
continue
|
||||
with Transaction().set_context({'active_id': invoice.id}):
|
||||
session_id, _, _ = PayInvoice.create()
|
||||
pay_invoice = PayInvoice(session_id)
|
||||
pay_invoice.start.currency = transaction.currency
|
||||
pay_invoice.start.currency_digits = (transaction
|
||||
.currency_digits)
|
||||
pay_invoice.start.description = transaction.description
|
||||
pay_invoice.start.journal = transaction.gateway.journal
|
||||
pay_invoice.start.date = transaction.date
|
||||
pay_invoice.start.amount = transaction.amount
|
||||
if invoice.total_amount != transaction.amount:
|
||||
min_percent_writeoff = invoice.total_amount * (1 -
|
||||
transaction.gateway.writeoff_amount_percent)
|
||||
max_percent_writeoff = invoice.total_amount * (1 +
|
||||
transaction.gateway.writeoff_amount_percent)
|
||||
[setattr(pay_invoice.ask, f, v)
|
||||
for f, v in pay_invoice.default_ask(None)
|
||||
.iteritems()]
|
||||
|
||||
if (min_percent_writeoff < transaction.amount <
|
||||
max_percent_writeoff
|
||||
or transaction.amount > invoice.amount_to_pay):
|
||||
pay_invoice.ask.type = 'writeoff'
|
||||
pay_invoice.ask.journal_writeoff = (transaction
|
||||
.gateway.journal_writeoff)
|
||||
else:
|
||||
pay_invoice.ask.type = 'partial'
|
||||
pay_invoice.transition_pay()
|
||||
PayInvoice.delete(session_id)
|
||||
to_update.append(transaction)
|
||||
|
||||
super(AccountPaymentGatewayTransaction, cls).confirm(to_update)
|
||||
|
|
|
@ -31,3 +31,8 @@ class Invoice:
|
|||
if transaction.origin == invoice:
|
||||
result[name][invoice.id] += transaction.amount
|
||||
return result
|
||||
|
||||
@classmethod
|
||||
def workflow_to_posted(cls, invoices):
|
||||
cls.validate_invoice(invoices)
|
||||
cls.post(invoices)
|
||||
|
|
Loading…
Reference in a new issue