From 6f4c8f0351feeae9dfd668fcd05111a90cfc5ee0 Mon Sep 17 00:00:00 2001 From: Stefan Rijnhart Date: Sat, 10 Mar 2012 14:51:08 +0100 Subject: [PATCH] [RFR] Adapt NL Clieop module to API changes in 6.1 [FIX] Clieop export counter per day was always 1 --- .../account_banking_nl_clieop.py | 30 ++++++++++--------- .../wizard/export_clieop.py | 25 +++++++++++----- 2 files changed, 34 insertions(+), 21 deletions(-) diff --git a/account_banking_nl_clieop/account_banking_nl_clieop.py b/account_banking_nl_clieop/account_banking_nl_clieop.py index eae9a88e1..69fc306db 100644 --- a/account_banking_nl_clieop/account_banking_nl_clieop.py +++ b/account_banking_nl_clieop/account_banking_nl_clieop.py @@ -59,7 +59,7 @@ class clieop_export(osv.osv): ('INCASSO', 'Direct Debit Batch'), ], 'File Type', size=7, readonly=True, select=True), 'date_generated': - fields.datetime('Generation Date', readonly=True, select=True), + fields.date('Generation Date', readonly=True, select=True), 'file': fields.binary('ClieOp File', readonly=True), 'state': @@ -69,24 +69,26 @@ class clieop_export(osv.osv): ('done', 'Reconciled'), ], 'State', readonly=True), } - def _get_daynr(self, cursor, uid, ids, context): + def get_daynr(self, cr, uid, context=None): ''' Return highest day number ''' - last = cursor.execute('SELECT max(daynumber) ' - 'FROM banking_export_clieop ' - 'WHERE date_generated = "%s"' % - date.today().strftime('%Y-%m-%d') - ).fetchone() - if last: - return int(last) +1 - return 1 + last = 1 + last_ids = self.search(cr, uid, [ + ('date_generated', '=', + fields.date.context_today(cr,uid,context)) + ], context=context) + if last_ids: + last = 1 + max([x['daynumber'] for x in self.read( + cr, uid, last_ids, ['daynumber'], + context=context)]) + return last _defaults = { - 'date_generated': lambda *a: date.today().strftime('%Y-%m-%d'), - 'duplicates': lambda *a: 1, - 'state': lambda *a: 'draft', - 'daynumber': _get_daynr, + 'date_generated': fields.date.context_today, + 'duplicates': 1, + 'state': 'draft', + 'daynumber': get_daynr, } clieop_export() diff --git a/account_banking_nl_clieop/wizard/export_clieop.py b/account_banking_nl_clieop/wizard/export_clieop.py index 2088c8d98..36b00049c 100644 --- a/account_banking_nl_clieop/wizard/export_clieop.py +++ b/account_banking_nl_clieop/wizard/export_clieop.py @@ -237,11 +237,15 @@ class banking_export_clieop_wizard(osv.osv_memory): # Just once: create clieop file our_account_owner = payment_order.mode.bank_id.owner_name \ or payment_order.mode.bank_id.partner_id.name - our_account_nr = payment_order.mode.bank_id.acc_number - if not our_account_nr and payment_order.mode.bank_id.iban: - our_account_nr = sepa.IBAN( - payment_order.mode.bank_id.iban - ).localized_BBAN + + if payment_order.mode.bank_id.state == 'iban': + our_account_nr = payment_order.mode.bank_id.acc_number_domestic + if not our_account_nr: + our_account_nr = sepa.IBAN( + payment_order.mode.bank_id.acc_number + ).localized_BBAN + else: + our_account_nr = payment_order.mode.bank_id.acc_number if not our_account_nr: raise osv.except_osv( _('Error'), @@ -255,6 +259,9 @@ class banking_export_clieop_wizard(osv.osv_memory): execution_date = clieop_export['execution_date'], name_sender = our_account_owner, accountno_sender = our_account_nr, + seqno = self.pool.get( + 'banking.export.clieop').get_daynr( + cursor, uid, context=context), test = clieop_export['test'] ) @@ -292,7 +299,11 @@ class banking_export_clieop_wizard(osv.osv_memory): ) if line.communication2: kwargs['messages'] = [line.communication2] - other_account_nr = line.bank_id.acc_number + other_account_nr = ( + line.bank_id.state == 'iban' and + line.bank_id.acc_number_domestic or + line.bank_id.acc_number + ) iban = sepa.IBAN(other_account_nr) # Is this an IBAN account? if iban.valid: @@ -351,7 +362,7 @@ class banking_export_clieop_wizard(osv.osv_memory): Cancel the ClieOp: just drop the file ''' clieop_export = self.read(cursor, uid, ids, ['file_id'], context)[0] - self.pool.get('banking.export.clieop').unlink(cursor, uid, clieop_export['file_id']) + self.pool.get('banking.export.clieop').unlink(cursor, uid, clieop_export['file_id'][0]) return {'type': 'ir.actions.act_window_close'} def save_clieop(self, cursor, uid, ids, context):