Added refunded state and refund transition to transactions

This commit is contained in:
jmartin 2016-04-01 13:43:53 +02:00
parent 273219ac06
commit 8cc7f37f1d
2 changed files with 20 additions and 0 deletions

View File

@ -82,6 +82,7 @@ class AccountPaymentGatewayTransaction(Workflow, ModelSQL, ModelView):
('authorized', 'Authorized'),
('done', 'Done'),
('cancel', 'Canceled'),
('refunded', 'Refunded'),
], 'State', readonly=True)
log = fields.Text("Log", depends=['state'], states=READONLY_IF_NOT_DRAFT)
@ -108,7 +109,9 @@ class AccountPaymentGatewayTransaction(Workflow, ModelSQL, ModelView):
('pending', 'done'),
('authorized', 'cancel'),
('authorized', 'done'),
('authorized', 'refunded'),
('done', 'cancel'),
('done', 'refunded'),
))
cls._buttons.update({
'cancel': {
@ -130,6 +133,11 @@ class AccountPaymentGatewayTransaction(Workflow, ModelSQL, ModelView):
'draft', 'pending', 'authorized',
]),
},
'refund': {
'invisible': ~Eval('state').in_([
'authorized', 'done',
]),
},
})
@staticmethod
@ -245,3 +253,13 @@ class AccountPaymentGatewayTransaction(Workflow, ModelSQL, ModelView):
if hasattr(transaction, method_name):
getattr(transaction, method_name)()
pass
@classmethod
@ModelView.button
@Workflow.transition('refunded')
def refund(cls, transactions):
for transaction in transactions:
method_name = 'refund_%s' % transaction.gateway.method
if hasattr(transaction, method_name):
getattr(transaction, method_name)()
pass

View File

@ -42,6 +42,8 @@ this repository contains the full copyright notices and license terms. -->
icon="tryton-go-next"/>
<button name="authorized" string="Authorized"
icon="tryton-go-next"/>
<button name="refund" string="Refund"
icon="tryton-go-previous"/>
<button name="confirm" string="Confirm"
icon="tryton-go-next"/>
</group>