PEP8 on account_direct_debit

This commit is contained in:
Sandy Carter
2014-08-21 11:37:59 -04:00
parent e34b30866c
commit b6ea50c15f
8 changed files with 71 additions and 66 deletions

View File

@@ -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,

View File

@@ -2,7 +2,7 @@
############################################################################## ##############################################################################
# #
# Copyright (C) 2013 Therp BV (<http://therp.nl>). # Copyright (C) 2013 Therp BV (<http://therp.nl>).
# #
# All other contributions are (C) by their respective contributors # All other contributions are (C) by their respective contributors
# #
# All Rights Reserved # All Rights Reserved
@@ -22,6 +22,7 @@
# #
############################################################################## ##############################################################################
def migrate(cr, version): def migrate(cr, version):
if not version: if not version:
return return

View File

@@ -2,7 +2,7 @@
############################################################################## ##############################################################################
# #
# Copyright (C) 2013 Therp BV (<http://therp.nl>). # Copyright (C) 2013 Therp BV (<http://therp.nl>).
# #
# All other contributions are (C) by their respective contributors # All other contributions are (C) by their respective contributors
# #
# All Rights Reserved # All Rights Reserved
@@ -25,27 +25,29 @@
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
# rename field debit_move_line_id # rename field debit_move_line_id
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'),
]}) ]
})

View File

@@ -2,7 +2,7 @@
############################################################################## ##############################################################################
# #
# Copyright (C) 2011 - 2013 Therp BV (<http://therp.nl>). # Copyright (C) 2011 - 2013 Therp BV (<http://therp.nl>).
# #
# All other contributions are (C) by their respective contributors # All other contributions are (C) by their respective contributors
# #
# All Rights Reserved # All Rights Reserved
@@ -33,13 +33,13 @@ credited afterwards. Such a creditation is called a storno.
Invoice workflow: Invoice workflow:
1 the sale leads to 1 the sale leads to
1300 Debtors 100 1300 Debtors 100
8000 Sales 100 8000 Sales 100
Balance: Balance:
Debtors 2000 | Debtors 2000 |
Sales | 2000 Sales | 2000
2 an external booking takes place 2 an external booking takes place
1100 Bank 100 1100 Bank 100
@@ -59,11 +59,11 @@ This module implements the following diversion:
2000 Transfer account 100 | 2000 Transfer account 100 |
1300 Debtors | 100 1300 Debtors | 100
Reconciliation takes place between 1 and 2a. Reconciliation takes place between 1 and 2a.
The invoice gets set to state 'paid', and 'reconciled' = True The invoice gets set to state 'paid', and 'reconciled' = True
Balance: Balance:
Debtors 0 | Debtors 0 |
Transfer account 2000 | Transfer account 2000 |
Bank 0 | Bank 0 |
Sales | 2000 Sales | 2000
@@ -76,7 +76,7 @@ Balance:
Reconciliation takes place between 3a and 2a Reconciliation takes place between 3a and 2a
Balance: Balance:
Debtors 0 | Debtors 0 |
Transfer account 0 | Transfer account 0 |
Bank 2000 | Bank 2000 |
Sales | 2000 Sales | 2000
@@ -84,55 +84,57 @@ Balance:
4 a storno from invoice [1] triggers a new booking on the bank account 4 a storno from invoice [1] triggers a new booking on the bank account
1300 Debtors 100 | 1300 Debtors 100 |
1100 Bank | 100 1100 Bank | 100
Balance: Balance:
Debtors 100 | Debtors 100 |
Transfer account 0 | Transfer account 0 |
Bank 1900 | Bank 1900 |
Sales | 2000 Sales | 2000
The reconciliation of 2a is undone. The booking of 2a is reconciled The reconciliation of 2a is undone. The booking of 2a is reconciled
with the booking of 4 instead. with the booking of 4 instead.
The payment line attribute 'storno' is set to True and the invoice The payment line attribute 'storno' is set to True and the invoice
state is no longer 'paid'. state is no longer 'paid'.
Two cases need to be distinguisted: Two cases need to be distinguisted:
1) If the storno is a manual storno from the partner, the invoice is set to 1) If the storno is a manual storno from the partner, the invoice is set to
state 'debit_denied', with 'reconciled' = False state 'debit_denied', with 'reconciled' = False
This module implements this option by allowing the bank module to call This module implements this option by allowing the bank module to call
netsvc.LocalService("workflow").trg_validate( netsvc.LocalService("workflow").trg_validate(
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)
Should also be adding a log entry on the invoice for tracing purposes Should also be adding a log entry on the invoice for tracing purposes
self._log_event(cr, uid, ids, -1.0, 'Debit denied') self._log_event(cr, uid, ids, -1.0, 'Debit denied')
If not for that funny comment If not for that funny comment
"#TODO: implement messages system" in account/invoice.py "#TODO: implement messages system" in account/invoice.py
Repeating non-fatal fatal errors need to be dealt with manually by checking Repeating non-fatal fatal errors need to be dealt with manually by checking
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"
def __init__(self, pool, cr): def __init__(self, pool, cr):
""" """
Adding a state to the hardcoded state list of the inherited Adding a state to the hardcoded state list of the inherited
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')
invoice_obj._columns['state'].selection.append( invoice_obj._columns['state'].selection.append(
@@ -144,8 +146,8 @@ class account_invoice(orm.Model):
number = self.read( number = self.read(
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):
@@ -154,9 +156,9 @@ class account_invoice(orm.Model):
return True return True
def test_undo_debit_denied(self, cr, uid, ids, context=None): def test_undo_debit_denied(self, cr, uid, ids, context=None):
""" """
Called from the workflow. Used to unset paid state on Called from the workflow. Used to unset paid state on
invoices that were paid with bank transfers which are being cancelled invoices that were paid with bank transfers which are being cancelled
""" """
for invoice in self.read(cr, uid, ids, ['reconciled'], context): for invoice in self.read(cr, uid, ids, ['reconciled'], context):
if not invoice['reconciled']: if not invoice['reconciled']:

View File

@@ -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

View File

@@ -1,16 +1,15 @@
# -*- 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'
def test_undo_done(self, cr, uid, ids, context=None): def test_undo_done(self, cr, uid, ids, context=None):
""" """
Called from the workflow. Used to unset done state on Called from the workflow. Used to unset done state on
payment orders that were reconciled with bank transfers payment orders that were reconciled with bank transfers
which are being cancelled which are being cancelled
""" """
for order in self.browse(cr, uid, ids, context=context): for order in self.browse(cr, uid, ids, context=context):
if order.payment_order_type == 'debit': if order.payment_order_type == 'debit':

View File

@@ -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:
@@ -104,7 +104,7 @@ class payment_line(orm.Model):
return reconcile_id return reconcile_id
def get_storno_account_id(self, cr, uid, payment_line_id, amount, def get_storno_account_id(self, cr, uid, payment_line_id, amount,
currency, context=None): currency, context=None):
""" """
Check the match of the arguments, and return the account associated Check the match of the arguments, and return the account associated
with the storno. with the storno.

View File

@@ -2,7 +2,7 @@
############################################################################## ##############################################################################
# #
# Copyright (C) 2013 Therp BV (<http://therp.nl>). # Copyright (C) 2013 Therp BV (<http://therp.nl>).
# #
# All other contributions are (C) by their respective contributors # All other contributions are (C) by their respective contributors
# #
# All Rights Reserved # All Rights Reserved