Import transactions

This commit is contained in:
resteve 2016-04-06 17:50:58 +02:00
parent 3664a766a8
commit 2b3ff56196
5 changed files with 174 additions and 5 deletions

View File

@ -1,11 +1,12 @@
# This file is part account_payment_gateway module for Tryton.
# The COPYRIGHT file at the top level of this repository contains
# the full copyright notices and license terms.
from uuid import uuid4
from datetime import datetime
from trytond.model import ModelSQL, ModelView, Workflow, fields
from trytond.pool import Pool
from trytond.pyson import Eval, If
from trytond.transaction import Transaction
from uuid import uuid4
__all__ = ['AccountPaymentGateway', 'AccountPaymentGatewayTransaction']
READONLY_IF_NOT_DRAFT = {'readonly': Eval('state') != 'draft'}
@ -22,11 +23,28 @@ class AccountPaymentGateway(ModelSQL, ModelView):
])
active = fields.Boolean('Active')
method = fields.Selection('get_methods', 'Method', required=True)
mode = fields.Selection([
('live', 'Live'),
('sandbox', 'Sandbox'),
], 'Mode', required=True)
journal = fields.Many2One('account.journal', 'Journal', required=True)
journal_writeoff = fields.Many2One('account.journal', 'Write Off Journal',
required=True)
writeoff_amount_percent = fields.Numeric('Write Off (%)', digits=(8, 4),
required=True)
from_transactions = fields.DateTime('From Transactions',
help='This date is last import (filter)', required=True)
to_transactions = fields.DateTime('To Transactions',
help='This date is to import (filter)')
scheduler = fields.Boolean('Scheduler',
help='Import transactions from Gateway')
@classmethod
def __setup__(cls):
super(AccountPaymentGateway, cls).__setup__()
cls._buttons.update({
'import_transactions': {},
})
@staticmethod
def default_company():
@ -36,11 +54,41 @@ class AccountPaymentGateway(ModelSQL, ModelView):
def default_active():
return True
@staticmethod
def default_from_transactions():
return datetime.now()
@classmethod
def get_methods(cls):
res = [(None, '')]
return res
@staticmethod
def default_mode():
return 'live'
@classmethod
@ModelView.button
def import_transactions(self, gateways):
"""
Import Transactions from Gateway APP
"""
for gateway in gateways:
import_transaction = getattr(gateway, 'import_transactions_%s' %
gateway.method)
import_transaction()
@classmethod
def import_gateway(cls):
"""
Import gateways transactions:
"""
gateways = cls.search([
('scheduler', '=', True),
])
cls.import_transactions(gateways)
return True
class AccountPaymentGatewayTransaction(Workflow, ModelSQL, ModelView):
'''Account Payment Gateway Transaction'''

View File

@ -36,6 +36,20 @@ this repository contains the full copyright notices and license terms. -->
<field name="group" ref="group_account_payment_gateway_admin"/>
</record>
<!-- cron -->
<record model="ir.cron" id="cron_gateway_import_transaction">
<field name="name">Payment Gateway - Import Transactions</field>
<field name="request_user" ref="res.user_admin"/>
<field name="user" ref="res.user_trigger"/>
<field name="active" eval="True"/>
<field name="interval_number">1</field>
<field name="interval_type">days</field>
<field name="number_calls">-1</field>
<field name="repeat_missed" eval="False"/>
<field name="model">account.payment.gateway</field>
<field name="function">import_gateway</field>
</record>
<!-- account.payment.gateway -->
<record model="ir.ui.view" id="account_payment_gateway_view_form">
<field name="model">account.payment.gateway</field>

View File

@ -26,6 +26,10 @@ msgctxt "field:account.payment.gateway,create_uid:"
msgid "Create User"
msgstr "Usuari creació"
msgctxt "field:account.payment.gateway,from_transactions:"
msgid "From Transactions"
msgstr "Desde transaccions"
msgctxt "field:account.payment.gateway,id:"
msgid "ID"
msgstr "ID"
@ -42,6 +46,10 @@ msgctxt "field:account.payment.gateway,method:"
msgid "Method"
msgstr "Mètode"
msgctxt "field:account.payment.gateway,mode:"
msgid "Mode"
msgstr "Mode"
msgctxt "field:account.payment.gateway,name:"
msgid "Name"
msgstr "Nom"
@ -50,6 +58,14 @@ msgctxt "field:account.payment.gateway,rec_name:"
msgid "Name"
msgstr "Nom"
msgctxt "field:account.payment.gateway,scheduler:"
msgid "Scheduler"
msgstr "Planificació"
msgctxt "field:account.payment.gateway,to_transactions:"
msgid "To Transactions"
msgstr "A transaccions"
msgctxt "field:account.payment.gateway,write_date:"
msgid "Write Date"
msgstr "Data modificació"
@ -150,6 +166,18 @@ msgctxt "field:account.payment.type,gateway:"
msgid "Gateway"
msgstr "Pasarel·la"
msgctxt "help:account.payment.gateway,from_transactions:"
msgid "This date is last import (filter)"
msgstr "La data última importació (filtre)"
msgctxt "help:account.payment.gateway,scheduler:"
msgid "Import transactions from Gateway"
msgstr "Importa transaccions desde la pasarel·la de pagament"
msgctxt "help:account.payment.gateway,to_transactions:"
msgid "This date is to import (filter)"
msgstr "La data inal de la importació (filtre)"
msgctxt "model:account.payment.gateway,name:"
msgid "Account Payment Gateway"
msgstr "Passarel·la de pagament"
@ -201,6 +229,10 @@ msgctxt ""
msgid "Refunded"
msgstr "Devolució"
msgctxt "model:ir.cron,name:cron_gateway_import_transaction"
msgid "Payment Gateway - Import Transactions"
msgstr "Pasarel·la de pagament - Importa transaccions"
msgctxt "model:ir.sequence.type,name:sequence_type_payment_gateway"
msgid "Payment Gateway"
msgstr "Pasarel·la pagament"
@ -229,6 +261,14 @@ msgctxt "model:res.group,name:group_account_payment_gateway_admin"
msgid "Account Payment Gateway Administration"
msgstr "Administració pasarel·la de pagament"
msgctxt "selection:account.payment.gateway,mode:"
msgid "Live"
msgstr "Producció"
msgctxt "selection:account.payment.gateway,mode:"
msgid "Sandbox"
msgstr "Sandbox"
msgctxt "selection:account.payment.gateway.transaction,state:"
msgid "Authorized"
msgstr "Autoritzat"
@ -305,6 +345,10 @@ msgctxt "view:account.payment.gateway.transaction:"
msgid "Transactions"
msgstr "Transaccions"
msgctxt "view:account.payment.gateway:"
msgid "Actions"
msgstr "Accions"
msgctxt "view:account.payment.gateway:"
msgid "Configuration"
msgstr "Configuració"
@ -316,3 +360,7 @@ msgstr "Pasarel·la"
msgctxt "view:account.payment.gateway:"
msgid "Gateways"
msgstr "Pasarel·les"
msgctxt "view:account.payment.gateway:"
msgid "Import Transactions"
msgstr "Importa transaccions"

View File

@ -26,6 +26,10 @@ msgctxt "field:account.payment.gateway,create_uid:"
msgid "Create User"
msgstr "Usuario creación"
msgctxt "field:account.payment.gateway,from_transactions:"
msgid "From Transactions"
msgstr "Desde transacciones"
msgctxt "field:account.payment.gateway,id:"
msgid "ID"
msgstr "ID"
@ -42,6 +46,10 @@ msgctxt "field:account.payment.gateway,method:"
msgid "Method"
msgstr "Método"
msgctxt "field:account.payment.gateway,mode:"
msgid "Mode"
msgstr "Modo"
msgctxt "field:account.payment.gateway,name:"
msgid "Name"
msgstr "Nombre"
@ -50,6 +58,14 @@ msgctxt "field:account.payment.gateway,rec_name:"
msgid "Name"
msgstr "Nombre"
msgctxt "field:account.payment.gateway,scheduler:"
msgid "Scheduler"
msgstr "Acciones planificadas"
msgctxt "field:account.payment.gateway,to_transactions:"
msgid "To Transactions"
msgstr "A transacciones"
msgctxt "field:account.payment.gateway,write_date:"
msgid "Write Date"
msgstr "Fecha modificación"
@ -150,6 +166,18 @@ msgctxt "field:account.payment.type,gateway:"
msgid "Gateway"
msgstr "Pasarela"
msgctxt "help:account.payment.gateway,from_transactions:"
msgid "This date is last import (filter)"
msgstr "La fecha de la última importación (filtro)"
msgctxt "help:account.payment.gateway,scheduler:"
msgid "Import transactions from Gateway"
msgstr "Importa transacciones desde pasarela de pago"
msgctxt "help:account.payment.gateway,to_transactions:"
msgid "This date is to import (filter)"
msgstr "La fecha final de importación (filtro)"
msgctxt "model:account.payment.gateway,name:"
msgid "Account Payment Gateway"
msgstr "Pasarela de pago"
@ -201,6 +229,10 @@ msgctxt ""
msgid "Refunded"
msgstr "Devolución"
msgctxt "model:ir.cron,name:cron_gateway_import_transaction"
msgid "Payment Gateway - Import Transactions"
msgstr "Pasarelas de pagos - Importación transacciones"
msgctxt "model:ir.sequence.type,name:sequence_type_payment_gateway"
msgid "Payment Gateway"
msgstr "Pasarela de pago"
@ -229,6 +261,14 @@ msgctxt "model:res.group,name:group_account_payment_gateway_admin"
msgid "Account Payment Gateway Administration"
msgstr "Administración pasarela de pago"
msgctxt "selection:account.payment.gateway,mode:"
msgid "Live"
msgstr "Producción"
msgctxt "selection:account.payment.gateway,mode:"
msgid "Sandbox"
msgstr "Sandbox"
msgctxt "selection:account.payment.gateway.transaction,state:"
msgid "Authorized"
msgstr "Autorizado"
@ -305,6 +345,10 @@ msgctxt "view:account.payment.gateway.transaction:"
msgid "Transactions"
msgstr "Transacciones"
msgctxt "view:account.payment.gateway:"
msgid "Actions"
msgstr "Acciones"
msgctxt "view:account.payment.gateway:"
msgid "Configuration"
msgstr "Configuración"
@ -316,3 +360,7 @@ msgstr "Pasarela"
msgctxt "view:account.payment.gateway:"
msgid "Gateways"
msgstr "Pasarelas"
msgctxt "view:account.payment.gateway:"
msgid "Import Transactions"
msgstr "Importar transacciones"

View File

@ -6,16 +6,27 @@ this repository contains the full copyright notices and license terms. -->
<field name="name"/>
<label name="active"/>
<field name="active"/>
<label name="method"/>
<field name="method"/>
<label name="journal"/>
<field name="journal"/>
<label name="journal_writeoff"/>
<field name="journal_writeoff"/>
<label name="writeoff_amount_percent"/>
<field name="writeoff_amount_percent" factor="100"/>
<notebook colspan="4">
<page string="Configuration" id="configuration">
<notebook colspan="6">
<page string="Actions" id="actions" col="6">
<button name="import_transactions" string="Import Transactions"/>
<label name="from_transactions"/>
<field name="from_transactions"/>
<label name="to_transactions"/>
<field name="to_transactions"/><newline/>
</page>
<page string="Configuration" id="configuration" col="6">
<label name="scheduler"/>
<field name="scheduler"/>
<label name="method"/>
<field name="method"/>
<label name="mode"/>
<field name="mode"/>
</page>
</notebook>
</form>