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