PEP8 on account_banking_payment_export

This commit is contained in:
Sandy Carter
2014-08-21 12:59:50 -04:00
parent a4ad7a0fbd
commit 3b4cfde486
5 changed files with 126 additions and 98 deletions

View File

@@ -3,7 +3,7 @@
#
# Copyright (C) 2009 EduSense BV (<http://www.edusense.nl>).
# (C) 2011 - 2013 Therp BV (<http://therp.nl>).
#
#
# All other contributions are (C) by their respective contributors
#
# All Rights Reserved
@@ -41,7 +41,7 @@
'workflow/account_payment.xml',
],
'description': '''
This addon adds payment reconciliation infrastructure to the Banking Addons.
This addon adds payment reconciliation infrastructure to the Banking Addons.
* Extends payments for digital banking:
+ Adapted workflow in payments to reflect banking operations

View File

@@ -3,7 +3,7 @@
#
# Copyright (C) 2009 EduSense BV (<http://www.edusense.nl>).
# (C) 2011 - 2013 Therp BV (<http://therp.nl>).
#
#
# All other contributions are (C) by their respective contributors
#
# All Rights Reserved
@@ -32,14 +32,12 @@ class banking_import_line(orm.TransientModel):
'payment_order_id': fields.many2one(
'payment.order', 'Payment order'),
'transaction_type': fields.selection([
# Add payment order related transaction types
('invoice', 'Invoice payment'),
('payment_order_line', 'Payment from a payment order'),
('payment_order', 'Aggregate payment order'),
('storno', 'Canceled debit order'),
('bank_costs', 'Bank costs'),
('unknown', 'Unknown'),
], 'Transaction type'),
}
# Add payment order related transaction types
('invoice', 'Invoice payment'),
('payment_order_line', 'Payment from a payment order'),
('payment_order', 'Aggregate payment order'),
('storno', 'Canceled debit order'),
('bank_costs', 'Bank costs'),
('unknown', 'Unknown'),
], 'Transaction type'),
}

View File

@@ -3,7 +3,7 @@
#
# Copyright (C) 2009 EduSense BV (<http://www.edusense.nl>).
# (C) 2011 - 2013 Therp BV (<http://therp.nl>).
#
#
# All other contributions are (C) by their respective contributors
#
# All Rights Reserved
@@ -27,14 +27,16 @@ from openerp.osv import orm, fields
from openerp import netsvc
from openerp.tools.translate import _
from openerp.addons.decimal_precision import decimal_precision as dp
from openerp.addons.account_banking.parsers.models import mem_bank_transaction as bt
from openerp.addons.account_banking.parsers.models import (
mem_bank_transaction as bt
)
class banking_import_transaction(orm.Model):
_inherit = 'banking.import.transaction'
def _match_payment_order(
self, cr, uid, trans, log, order_type='payment', context=None):
self, cr, uid, trans, log, order_type='payment', context=None):
def equals_order_amount(payment_order, transferred_amount):
if (not hasattr(payment_order, 'payment_order_type')
@@ -60,25 +62,26 @@ class banking_import_transaction(orm.Model):
if len(candidates) > 0:
# retrieve the common account_id, if any
account_id = False
if (candidates[0].line_ids[0].transit_move_line_id):
for line in candidates[0].line_ids[0].transit_move_line_id.move_id.line_id:
transit_move_lines = candidates[0].line_ids[0].transit_move_line_id
if transit_move_lines:
for line in transit_move_lines.move_id.line_id:
if line.account_id.type == 'other':
account_id = line.account_id.id
break
return dict(
move_line_ids = False,
match_type = 'payment_order',
payment_order_ids = [x.id for x in candidates],
account_id = account_id,
partner_id = False,
partner_bank_id = False,
reference = False,
move_line_ids=False,
match_type='payment_order',
payment_order_ids=[x.id for x in candidates],
account_id=account_id,
partner_id=False,
partner_bank_id=False,
reference=False,
type='general',
)
)
return False
def _match_storno(
self, cr, uid, trans, log, context=None):
self, cr, uid, trans, log, context=None):
payment_line_obj = self.pool.get('payment.line')
line_ids = payment_line_obj.search(
cr, uid, [
@@ -93,21 +96,21 @@ class banking_import_transaction(orm.Model):
trans.statement_id.currency, context=None)
if account_id:
return dict(
account_id = account_id,
match_type = 'storno',
payment_line_id = line_ids[0],
account_id=account_id,
match_type='storno',
payment_line_id=line_ids[0],
move_line_ids=False,
partner_id=False,
partner_bank_id=False,
reference=False,
type='customer',
)
)
# TODO log the reason why there is no result for transfers marked
# as storno
return False
def _match_payment(self, cr, uid, trans, payment_lines,
partner_ids, bank_account_ids, log, linked_payments):
partner_ids, bank_account_ids, log, linked_payments):
'''
Find the payment order belonging to this reference - if there is one
This is the easiest part: when sending payments, the returned bank info
@@ -132,7 +135,7 @@ class banking_import_transaction(orm.Model):
digits = dp.get_precision('Account')(cr)[1]
candidates = [
line for line in payment_lines
if (line.communication == trans.reference
if (line.communication == trans.reference
and round(line.amount, digits) == -round(
trans.statement_line_id.amount, digits)
and bank_match(trans.remote_account, line.bank_id))
@@ -145,15 +148,15 @@ class banking_import_transaction(orm.Model):
move_info = self._get_move_info(
cr, uid, [candidate.move_line_id.id])
move_info.update({
'match_type': 'payment',
'payment_line_id': candidate.id,
})
'match_type': 'payment',
'payment_line_id': candidate.id,
})
return move_info
return False
def _confirm_storno(
self, cr, uid, transaction_id, context=None):
self, cr, uid, transaction_id, context=None):
"""
Creation of the reconciliation has been delegated to
*a* direct debit module, to allow for various direct debit styles
@@ -167,18 +170,18 @@ class banking_import_transaction(orm.Model):
_("No direct debit order item"))
reconcile_id = payment_line_pool.debit_storno(
cr, uid,
transaction.payment_line_id.id,
transaction.payment_line_id.id,
transaction.statement_line_id.amount,
transaction.statement_line_id.currency,
transaction.storno_retry,
context=context)
statement_line_pool.write(
cr, uid, transaction.statement_line_id.id,
cr, uid, transaction.statement_line_id.id,
{'reconcile_id': reconcile_id}, context=context)
transaction.refresh()
def _confirm_payment_order(
self, cr, uid, transaction_id, context=None):
self, cr, uid, transaction_id, context=None):
"""
Creation of the reconciliation has been delegated to
*a* direct debit module, to allow for various direct debit styles
@@ -197,11 +200,11 @@ class banking_import_transaction(orm.Model):
transaction.statement_line_id.currency,
context=context)
statement_line_pool.write(
cr, uid, transaction.statement_line_id.id,
cr, uid, transaction.statement_line_id.id,
{'reconcile_id': reconcile_id}, context=context)
def _confirm_payment(
self, cr, uid, transaction_id, context=None):
self, cr, uid, transaction_id, context=None):
"""
Do some housekeeping on the payment line
then pass on to _reconcile_move
@@ -227,7 +230,7 @@ class banking_import_transaction(orm.Model):
uid, 'payment.order', order_id, 'done', cr)
def _cancel_payment(
self, cr, uid, transaction_id, context=None):
self, cr, uid, transaction_id, context=None):
"""
Do not support cancelling individual lines yet, because the workflow
of the payment order does not support reopening.
@@ -238,7 +241,7 @@ class banking_import_transaction(orm.Model):
"match type 'payment'"))
def _cancel_payment_order(
self, cr, uid, transaction_id, context=None):
self, cr, uid, transaction_id, context=None):
"""
"""
payment_order_obj = self.pool.get('payment.order')
@@ -259,7 +262,7 @@ class banking_import_transaction(orm.Model):
transaction.statement_line_id.currency)
def _cancel_storno(
self, cr, uid, transaction_id, context=None):
self, cr, uid, transaction_id, context=None):
"""
TODO: delegate unreconciliation to the direct debit module,
to allow for various direct debit styles
@@ -267,7 +270,7 @@ class banking_import_transaction(orm.Model):
payment_line_obj = self.pool.get('payment.line')
reconcile_obj = self.pool.get('account.move.reconcile')
transaction = self.browse(cr, uid, transaction_id, context=context)
if not transaction.payment_line_id:
raise orm.except_orm(
_("Cannot cancel link with storno"),
@@ -295,7 +298,8 @@ class banking_import_transaction(orm.Model):
raise orm.except_orm(
_("Cannot cancel link with storno"),
_("Line id not found"))
reconcile = cancel_line.reconcile_id or cancel_line.reconcile_partial_id
reconcile = (cancel_line.reconcile_id
or cancel_line.reconcile_partial_id)
lines_reconcile = reconcile.line_id or reconcile.line_partial_ids
if len(lines_reconcile) < 3:
# delete the full reconciliation
@@ -303,15 +307,15 @@ class banking_import_transaction(orm.Model):
else:
# we are left with a partial reconciliation
reconcile_obj.write(
cr, uid, reconcile.id,
{'line_partial_ids':
cr, uid, reconcile.id,
{'line_partial_ids':
[(6, 0, [x.id for x in lines_reconcile
if x.id != cancel_line.id])],
'line_id': [(6, 0, [])],
}, context)
# redo the original payment line reconciliation with the invoice
payment_line_obj.write(
cr, uid, transaction.payment_line_id.id,
cr, uid, transaction.payment_line_id.id,
{'storno': False}, context)
payment_line_obj.debit_reconcile(
cr, uid, transaction.payment_line_id.id, context)
@@ -333,7 +337,7 @@ class banking_import_transaction(orm.Model):
for transaction in self.browse(cr, uid, ids, context):
if transaction.match_type == 'payment_order':
if (transaction.payment_order_ids and not
transaction.payment_order_id):
transaction.payment_order_id):
res[transaction.id] = True
return res
@@ -354,7 +358,7 @@ class banking_import_transaction(orm.Model):
vals['payment_order_ids'] = [
(6, 0, move_info.get('payment_order_ids') or [])]
vals['payment_order_id'] = (
move_info.get('payment_order_ids', False) and
move_info.get('payment_order_ids', False) and
len(move_info['payment_order_ids']) == 1 and
move_info['payment_order_ids'][0]
)
@@ -388,17 +392,19 @@ class banking_import_transaction(orm.Model):
super(banking_import_transaction, self).__init__(pool, cr)
self.confirm_map.update({
'storno': banking_import_transaction._confirm_storno,
'payment_order': banking_import_transaction._confirm_payment_order,
'payment': banking_import_transaction._confirm_payment,
'payment_order_manual': banking_import_transaction._confirm_payment_order,
'payment_manual': banking_import_transaction._confirm_payment,
})
'storno': banking_import_transaction._confirm_storno,
'payment_order': banking_import_transaction._confirm_payment_order,
'payment': banking_import_transaction._confirm_payment,
'payment_order_manual': (
banking_import_transaction._confirm_payment_order),
'payment_manual': banking_import_transaction._confirm_payment,
})
self.cancel_map.update({
'storno': banking_import_transaction._cancel_storno,
'payment_order': banking_import_transaction._cancel_payment_order,
'payment': banking_import_transaction._cancel_payment,
'payment_order_manual': banking_import_transaction._cancel_payment_order,
'payment_manual': banking_import_transaction._cancel_payment,
})
'storno': banking_import_transaction._cancel_storno,
'payment_order': banking_import_transaction._cancel_payment_order,
'payment': banking_import_transaction._cancel_payment,
'payment_order_manual': (
banking_import_transaction._cancel_payment_order),
'payment_manual': banking_import_transaction._cancel_payment,
})

View File

@@ -3,7 +3,7 @@
#
# Copyright (C) 2009 EduSense BV (<http://www.edusense.nl>).
# (C) 2011 - 2013 Therp BV (<http://therp.nl>).
#
#
# All other contributions are (C) by their respective contributors
#
# All Rights Reserved
@@ -53,19 +53,23 @@ class banking_transaction_wizard(orm.TransientModel):
sign = 1
else:
sign = -1
total = (payment_order.total + sign *
total = (payment_order.total + sign *
transaction_id.statement_line_id.amount)
if not self.pool.get('res.currency').is_zero(
cr, uid, transaction_id.statement_line_id.statement_id.currency, total):
cr, uid,
transaction_id.statement_line_id.statement_id.currency,
total):
raise orm.except_orm(
_('Error'),
_('When matching a payment order, the amounts have to '
'match exactly'))
if payment_order.mode and payment_order.mode.transfer_account_id:
if (payment_order.mode
and payment_order.mode.transfer_account_id):
transaction_id.statement_line_id.write({
'account_id': payment_order.mode.transfer_account_id.id,
})
'account_id': (
payment_order.mode.transfer_account_id.id),
})
write_vals.update(
{'payment_order_id': manual_payment_order_id,
'match_type': 'payment_order_manual'})
@@ -79,25 +83,40 @@ class banking_transaction_wizard(orm.TransientModel):
_columns = {
'payment_line_id': fields.related(
'import_transaction_id', 'payment_line_id',
string="Matching payment or storno",
type='many2one', relation='payment.line',
readonly=True),
'import_transaction_id',
'payment_line_id',
string="Matching payment or storno",
type='many2one',
relation='payment.line',
readonly=True,
),
'payment_order_ids': fields.related(
'import_transaction_id', 'payment_order_ids',
string="Matching payment orders",
type='many2many', relation='payment.order'),
'import_transaction_id',
'payment_order_ids',
string="Matching payment orders",
type='many2many',
relation='payment.order',
),
'payment_order_id': fields.related(
'import_transaction_id', 'payment_order_id',
string="Payment order to reconcile",
type='many2one', relation='payment.order'),
'import_transaction_id',
'payment_order_id',
string="Payment order to reconcile",
type='many2one',
relation='payment.order',
),
'manual_payment_order_id': fields.many2one(
'payment.order', 'Match this payment order',
domain=[('state', '=', 'sent')]),
'payment.order',
'Match this payment order',
domain=[
('state', '=', 'sent'),
],
),
'manual_payment_line_id': fields.many2one(
'payment.line', 'Match this payment line',
'payment.line',
'Match this payment line',
domain=[
('order_id.state', '=', 'sent'),
('date_done', '=', False),
]),
}
],
),
}

View File

@@ -3,7 +3,7 @@
#
# Copyright (C) 2009 EduSense BV (<http://www.edusense.nl>).
# (C) 2011 - 2013 Therp BV (<http://therp.nl>).
#
#
# All other contributions are (C) by their respective contributors
#
# All Rights Reserved
@@ -27,6 +27,7 @@ from openerp.osv import orm, fields
from openerp import netsvc
from openerp.tools.translate import _
class payment_line(orm.Model):
'''
Add some fields; make destination bank account
@@ -40,7 +41,7 @@ class payment_line(orm.Model):
'date_done': fields.date(
'Date Confirmed', select=True, readonly=True),
'transit_move_line_id': fields.many2one(
# this line is part of the credit side of move 2a
# this line is part of the credit side of move 2a
# from the documentation
'account.move.line', 'Debit move line',
readonly=True,
@@ -57,7 +58,7 @@ class payment_line(orm.Model):
account_direct_debit module.
"""
def get_storno_account_id(self, cr, uid, payment_line_id, amount,
currency_id, context=None):
currency_id, context=None):
"""
Hook for verifying a match of the payment line with the amount.
Return the account associated with the storno.
@@ -115,19 +116,21 @@ class payment_line(orm.Model):
if (not transit_move_line or not torec_move_line):
raise orm.except_orm(
_('Can not reconcile'),
_('No move line for line %s') % payment_line.name)
if torec_move_line.reconcile_id: # torec_move_line.reconcile_partial_id:
_('No move line for line %s') % payment_line.name
)
if torec_move_line.reconcile_id:
raise orm.except_orm(
_('Error'),
_('Move line %s has already been reconciled') %
_('Move line %s has already been reconciled') %
torec_move_line.name
)
if transit_move_line.reconcile_id or transit_move_line.reconcile_partial_id:
if (transit_move_line.reconcile_id
or transit_move_line.reconcile_partial_id):
raise orm.except_orm(
_('Error'),
_('Move line %s has already been reconciled') %
_('Move line %s has already been reconciled') %
transit_move_line.name
)
)
def is_zero(total):
return self.pool.get('res.currency').is_zero(
@@ -136,7 +139,7 @@ class payment_line(orm.Model):
line_ids = [transit_move_line.id, torec_move_line.id]
if torec_move_line.reconcile_partial_id:
line_ids = [
x.id for x in
x.id for x in
torec_move_line.reconcile_partial_id.line_partial_ids
] + [transit_move_line.id]
@@ -144,7 +147,9 @@ class payment_line(orm.Model):
vals = {
'type': 'auto',
'line_id': is_zero(total) and [(6, 0, line_ids)] or [(6, 0, [])],
'line_partial_ids': is_zero(total) and [(6, 0, [])] or [(6, 0, line_ids)],
'line_partial_ids': (is_zero(total)
and [(6, 0, [])]
or [(6, 0, line_ids)]),
}
if torec_move_line.reconcile_partial_id: