diff --git a/account_direct_debit/__openerp__.py b/account_direct_debit/__openerp__.py index 12fa1d227..ac5637bd7 100644 --- a/account_direct_debit/__openerp__.py +++ b/account_direct_debit/__openerp__.py @@ -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, diff --git a/account_direct_debit/migrations/7.0.2/post-migration.py b/account_direct_debit/migrations/7.0.2/post-migration.py index a6ec3af59..f5c72c672 100644 --- a/account_direct_debit/migrations/7.0.2/post-migration.py +++ b/account_direct_debit/migrations/7.0.2/post-migration.py @@ -2,7 +2,7 @@ ############################################################################## # # Copyright (C) 2013 Therp BV (). -# +# # All other contributions are (C) by their respective contributors # # All Rights Reserved @@ -22,6 +22,7 @@ # ############################################################################## + def migrate(cr, version): if not version: return diff --git a/account_direct_debit/migrations/7.0.2/pre-migration.py b/account_direct_debit/migrations/7.0.2/pre-migration.py index a167bca53..49c0db52f 100644 --- a/account_direct_debit/migrations/7.0.2/pre-migration.py +++ b/account_direct_debit/migrations/7.0.2/pre-migration.py @@ -2,7 +2,7 @@ ############################################################################## # # Copyright (C) 2013 Therp BV (). -# +# # All other contributions are (C) by their respective contributors # # All Rights Reserved @@ -25,27 +25,29 @@ 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 # rename field debit_move_line_id rename_columns(cr, { - 'payment_line': [ - ('debit_move_line_id', 'banking_addons_61_debit_move_line_id'), - ]}) + 'payment_line': [ + ('debit_move_line_id', 'banking_addons_61_debit_move_line_id'), + ] + }) diff --git a/account_direct_debit/model/account_invoice.py b/account_direct_debit/model/account_invoice.py index b522c45b9..fe2e92337 100644 --- a/account_direct_debit/model/account_invoice.py +++ b/account_direct_debit/model/account_invoice.py @@ -2,7 +2,7 @@ ############################################################################## # # Copyright (C) 2011 - 2013 Therp BV (). -# +# # All other contributions are (C) by their respective contributors # # All Rights Reserved @@ -33,13 +33,13 @@ credited afterwards. Such a creditation is called a storno. Invoice workflow: -1 the sale leads to +1 the sale leads to 1300 Debtors 100 8000 Sales 100 -Balance: - Debtors 2000 | - Sales | 2000 +Balance: + Debtors 2000 | + Sales | 2000 2 an external booking takes place 1100 Bank 100 @@ -59,11 +59,11 @@ This module implements the following diversion: 2000 Transfer account 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 Balance: - Debtors 0 | + Debtors 0 | Transfer account 2000 | Bank 0 | Sales | 2000 @@ -76,7 +76,7 @@ Balance: Reconciliation takes place between 3a and 2a Balance: - Debtors 0 | + Debtors 0 | Transfer account 0 | Bank 2000 | Sales | 2000 @@ -84,55 +84,57 @@ Balance: 4 a storno from invoice [1] triggers a new booking on the bank account 1300 Debtors 100 | 1100 Bank | 100 - + Balance: - Debtors 100 | + Debtors 100 | Transfer account 0 | Bank 1900 | 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. The payment line attribute 'storno' is set to True and the invoice state is no longer 'paid'. Two cases need to be distinguisted: 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 - + netsvc.LocalService("workflow").trg_validate( 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) 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 "#TODO: implement messages system" in account/invoice.py Repeating non-fatal fatal errors need to be dealt with manually by checking open invoices with a matured invoice- or due date. -""" +""" + class account_invoice(orm.Model): _inherit = "account.invoice" def __init__(self, pool, cr): - """ + """ 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! - 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') invoice_obj._columns['state'].selection.append( @@ -144,8 +146,8 @@ class account_invoice(orm.Model): number = self.read( cr, uid, invoice_id, ['number'], context=context)['number'] raise orm.except_orm( - _('Error !'), - _('You cannot set invoice \'%s\' to state \'debit denied\', ' + + _('Error !'), + _("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): @@ -154,9 +156,9 @@ class account_invoice(orm.Model): return True def test_undo_debit_denied(self, cr, uid, ids, context=None): - """ + """ 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): if not invoice['reconciled']: diff --git a/account_direct_debit/model/account_move_line.py b/account_direct_debit/model/account_move_line.py index 4cd7fab6c..12842e45f 100644 --- a/account_direct_debit/model/account_move_line.py +++ b/account_direct_debit/model/account_move_line.py @@ -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 diff --git a/account_direct_debit/model/account_payment.py b/account_direct_debit/model/account_payment.py index 1b4ce9298..b346efec3 100644 --- a/account_direct_debit/model/account_payment.py +++ b/account_direct_debit/model/account_payment.py @@ -1,16 +1,15 @@ # -*- 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' def test_undo_done(self, cr, uid, ids, context=None): - """ + """ Called from the workflow. Used to unset done state on 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): if order.payment_order_type == 'debit': diff --git a/account_direct_debit/model/payment_line.py b/account_direct_debit/model/payment_line.py index 2c6bf7c51..2be0993db 100644 --- a/account_direct_debit/model/payment_line.py +++ b/account_direct_debit/model/payment_line.py @@ -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 + partial_ids = [ + 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: @@ -104,7 +104,7 @@ class payment_line(orm.Model): return reconcile_id 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 with the storno. diff --git a/account_direct_debit/model/payment_order_create.py b/account_direct_debit/model/payment_order_create.py index b2bbdeb95..5625faac2 100644 --- a/account_direct_debit/model/payment_order_create.py +++ b/account_direct_debit/model/payment_order_create.py @@ -2,7 +2,7 @@ ############################################################################## # # Copyright (C) 2013 Therp BV (). -# +# # All other contributions are (C) by their respective contributors # # All Rights Reserved