mirror of
https://github.com/OCA/bank-payment.git
synced 2025-02-02 10:37:31 +02:00
PEP8 on account_direct_debit
This commit is contained in:
@@ -5,8 +5,8 @@
|
||||
# All Rights Reserved
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# it under the terms of the GNU Affero General Public License as published
|
||||
# by the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
|
||||
def migrate(cr, version):
|
||||
if not version:
|
||||
return
|
||||
|
||||
@@ -25,21 +25,22 @@
|
||||
import logging
|
||||
logger = logging.getLogger()
|
||||
|
||||
|
||||
def rename_columns(cr, column_spec):
|
||||
"""
|
||||
Rename table columns. Taken from OpenUpgrade.
|
||||
|
||||
:param column_spec: a hash with table keys, with lists of tuples as values. \
|
||||
Tuples consist of (old_name, new_name).
|
||||
:param column_spec: a hash with table keys, with lists of tuples as \
|
||||
values. Tuples consist of (old_name, new_name).
|
||||
|
||||
"""
|
||||
for table in column_spec.keys():
|
||||
for (old, new) in column_spec[table]:
|
||||
logger.info("table %s, column %s: renaming to %s",
|
||||
table, old, new)
|
||||
cr.execute('ALTER TABLE "%s" RENAME "%s" TO "%s"' % (table, old, new,))
|
||||
logger.info("table %s, column %s: renaming to %s", table, old, new)
|
||||
cr.execute('ALTER TABLE %s RENAME %s TO %s', (table, old, new,))
|
||||
cr.execute('DROP INDEX IF EXISTS "%s_%s_index"' % (table, old))
|
||||
|
||||
|
||||
def migrate(cr, version):
|
||||
if not version:
|
||||
return
|
||||
@@ -48,4 +49,5 @@ def migrate(cr, version):
|
||||
rename_columns(cr, {
|
||||
'payment_line': [
|
||||
('debit_move_line_id', 'banking_addons_61_debit_move_line_id'),
|
||||
]})
|
||||
]
|
||||
})
|
||||
|
||||
@@ -105,7 +105,8 @@ Two cases need to be distinguisted:
|
||||
uid, 'account.invoice', ids, 'debit_denied', cr)
|
||||
|
||||
2) If the storno is an error generated by the bank (assumingly non-fatal),
|
||||
the invoice is reopened for the next debit run. This is a call to existing
|
||||
the invoice is reopened for the next debit run.
|
||||
This is a call to existing
|
||||
|
||||
netsvc.LocalService("workflow").trg_validate(
|
||||
uid, 'account.invoice', ids, 'open_test', cr)
|
||||
@@ -121,6 +122,7 @@ Two cases need to be distinguisted:
|
||||
open invoices with a matured invoice- or due date.
|
||||
"""
|
||||
|
||||
|
||||
class account_invoice(orm.Model):
|
||||
_inherit = "account.invoice"
|
||||
|
||||
@@ -130,8 +132,8 @@ class account_invoice(orm.Model):
|
||||
model. The alternative is duplicating the field definition
|
||||
in columns but only one module can do that!
|
||||
|
||||
Maybe apply a similar trick when overriding the buttons' 'states' attributes
|
||||
in the form view, manipulating the xml in fields_view_get().
|
||||
Maybe apply a similar trick when overriding the buttons' 'states'
|
||||
attributes in the form view, manipulating the xml in fields_view_get().
|
||||
"""
|
||||
super(account_invoice, self).__init__(pool, cr)
|
||||
invoice_obj = pool.get('account.invoice')
|
||||
@@ -145,7 +147,7 @@ class account_invoice(orm.Model):
|
||||
cr, uid, invoice_id, ['number'], context=context)['number']
|
||||
raise orm.except_orm(
|
||||
_('Error !'),
|
||||
_('You cannot set invoice \'%s\' to state \'debit denied\', ' +
|
||||
_("You cannot set invoice '%s' to state 'debit denied', "
|
||||
'as it is still reconciled.') % number)
|
||||
self.write(cr, uid, ids, {'state': 'debit_denied'}, context=context)
|
||||
for inv_id, name in self.name_get(cr, uid, ids, context=context):
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
from operator import itemgetter
|
||||
from openerp.osv import fields, orm
|
||||
|
||||
|
||||
class account_move_line(orm.Model):
|
||||
_inherit = "account.move.line"
|
||||
|
||||
@@ -48,7 +49,7 @@ class account_move_line(orm.Model):
|
||||
AND pl.storno is false
|
||||
AND po.state != 'cancel') AS amount
|
||||
FROM account_move_line ml
|
||||
WHERE id IN %s""", (tuple(ids),))
|
||||
WHERE id IN %s""", (tuple(ids), ))
|
||||
r = dict(cr.fetchall())
|
||||
return r
|
||||
|
||||
@@ -80,12 +81,12 @@ class account_move_line(orm.Model):
|
||||
WHERE type=%s AND active)
|
||||
AND reconcile_id IS null
|
||||
AND debit > 0
|
||||
AND ''' + where + ' and ' + query), ('receivable',)+sql_args )
|
||||
AND ''' + where + ' and ' + query), ('receivable', ) + sql_args)
|
||||
|
||||
res = cr.fetchall()
|
||||
if not res:
|
||||
return [('id', '=', '0')]
|
||||
return [('id', 'in', map(lambda x:x[0], res))]
|
||||
return [('id', 'in', map(lambda x: x[0], res))]
|
||||
|
||||
def line2bank(self, cr, uid, ids, payment_mode_id, context=None):
|
||||
'''I have to inherit this function for direct debits to fix the
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from openerp.osv import orm, fields
|
||||
import netsvc
|
||||
from tools.translate import _
|
||||
from openerp.osv import orm
|
||||
|
||||
|
||||
class payment_order(orm.Model):
|
||||
_inherit = 'payment.order'
|
||||
|
||||
@@ -3,6 +3,7 @@ from openerp.osv import orm, fields
|
||||
import netsvc
|
||||
from tools.translate import _
|
||||
|
||||
|
||||
class payment_line(orm.Model):
|
||||
_inherit = 'payment.line'
|
||||
|
||||
@@ -22,15 +23,15 @@ class payment_line(orm.Model):
|
||||
:param payment_line_id: the single payment line id
|
||||
:param amount: the (signed) amount debited from the bank account
|
||||
:param currency: the bank account's currency *browse object*
|
||||
:param boolean storno_retry: when True, attempt to reopen the invoice, \
|
||||
set the invoice to 'Debit denied' otherwise.
|
||||
:param boolean storno_retry: when True, attempt to reopen the \
|
||||
invoice, set the invoice to 'Debit denied' otherwise.
|
||||
:return: an incomplete reconcile for the caller to fill
|
||||
:rtype: database id of an account.move.reconcile resource.
|
||||
"""
|
||||
|
||||
move_line_obj = self.pool.get('account.move.line')
|
||||
reconcile_obj = self.pool.get('account.move.reconcile')
|
||||
line = self.browse(cr, uid, payment_line_id)
|
||||
transit_move_line = line.transit_move_line_id
|
||||
reconcile_id = False
|
||||
if (line.transit_move_line_id and not line.storno and
|
||||
self.pool.get('res.currency').is_zero(
|
||||
@@ -43,14 +44,13 @@ class payment_line(orm.Model):
|
||||
# Actually, given the nature of a direct debit order and storno,
|
||||
# we should not need to take partial into account on the side of
|
||||
# the transit_move_line.
|
||||
if line.transit_move_line_id.reconcile_partial_id:
|
||||
reconcile_id = line.transit_move_line_id.reconcile_partial_id.id
|
||||
attribute = 'reconcile_partial_id'
|
||||
if len(line.transit_move_line_id.reconcile_id.line_partial_ids) == 2:
|
||||
if transit_move_line.reconcile_partial_id:
|
||||
reconcile_id = transit_move_line.reconcile_partial_id.id
|
||||
if len(transit_move_line.reconcile_id.line_partial_ids) == 2:
|
||||
# reuse the simple reconcile for the storno transfer
|
||||
reconcile_obj.write(
|
||||
cr, uid, reconcile_id, {
|
||||
'line_id': [(6, 0, line.transit_move_line_id.id)],
|
||||
'line_id': [(6, 0, transit_move_line.id)],
|
||||
'line_partial_ids': [(6, 0, [])],
|
||||
}, context=context)
|
||||
else:
|
||||
@@ -58,27 +58,27 @@ class payment_line(orm.Model):
|
||||
# and a new one for reconciling the storno transfer
|
||||
reconcile_obj.write(
|
||||
cr, uid, reconcile_id, {
|
||||
'line_partial_ids': [(3, line.transit_move_line_id.id)],
|
||||
'line_partial_ids': [(3, transit_move_line.id)],
|
||||
}, context=context)
|
||||
reconcile_id = reconcile_obj.create(
|
||||
cr, uid, {
|
||||
'type': 'auto',
|
||||
'line_id': [(6, 0, line.transit_move_line_id.id)],
|
||||
'line_id': [(6, 0, transit_move_line.id)],
|
||||
}, context=context)
|
||||
elif line.transit_move_line_id.reconcile_id:
|
||||
reconcile_id = line.transit_move_line_id.reconcile_id.id
|
||||
if len(line.transit_move_line_id.reconcile_id.line_id) == 2:
|
||||
elif transit_move_line.reconcile_id:
|
||||
reconcile_id = transit_move_line.reconcile_id.id
|
||||
if len(transit_move_line.reconcile_id.line_id) == 2:
|
||||
# reuse the simple reconcile for the storno transfer
|
||||
reconcile_obj.write(
|
||||
cr, uid, reconcile_id, {
|
||||
'line_id': [(6, 0, [line.transit_move_line_id.id])]
|
||||
'line_id': [(6, 0, [transit_move_line.id])]
|
||||
}, context=context)
|
||||
else:
|
||||
# split up the original reconcile in a partial one
|
||||
# and a new one for reconciling the storno transfer
|
||||
partial_ids = [
|
||||
x.id for x in line.transit_move_line_id.reconcile_id.line_id
|
||||
if x.id != line.transit_move_line_id.id
|
||||
x.id for x in transit_move_line.reconcile_id.line_id
|
||||
if x.id != transit_move_line.id
|
||||
]
|
||||
reconcile_obj.write(
|
||||
cr, uid, reconcile_id, {
|
||||
@@ -88,7 +88,7 @@ class payment_line(orm.Model):
|
||||
reconcile_id = reconcile_obj.create(
|
||||
cr, uid, {
|
||||
'type': 'auto',
|
||||
'line_id': [(6, 0, line.transit_move_line_id.id)],
|
||||
'line_id': [(6, 0, transit_move_line.id)],
|
||||
}, context=context)
|
||||
# mark the payment line for storno processed
|
||||
if reconcile_id:
|
||||
|
||||
Reference in New Issue
Block a user