~credativ/account-banking/fix-variable-error-6.0

« back to all changes in this revision

Viewing changes to account_banking/account_banking.py

  • Committer: Stefan Rijnhart
  • Date: 2011-04-26 20:41:31 UTC
  • Revision ID: stefan@therp.nl-20110426204131-hdtg529l979n9wdl
Migration to OpenERP 6.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
63
63
from osv import osv, fields
64
64
from tools.translate import _
65
65
from wizard.banktools import get_or_create_bank
 
66
import decimal_precision as dp
66
67
import pooler
67
68
import netsvc
68
69
 
183
184
    }
184
185
account_banking_imported_file()
185
186
 
 
187
class payment_mode_type(osv.osv):
 
188
    _name= 'payment.mode.type'
 
189
    _description= 'Payment Mode Type'
 
190
    _columns= {
 
191
        'name': fields.char(
 
192
            'Name', size=64, required=True,
 
193
            help='Payment Type'
 
194
            ),
 
195
        'code': fields.char(
 
196
            'Code', size=64, required=True,
 
197
            help='Specify the Code for Payment Type'
 
198
            ),
 
199
    }
 
200
 
 
201
payment_mode_type()
 
202
 
 
203
class payment_mode(osv.osv):
 
204
    ''' Restoring the payment type from version 5,
 
205
    used to select the export wizard (if any) '''
 
206
    _inherit = "payment.mode"
 
207
 
 
208
    def suitable_bank_types(self, cr, uid, payment_code=None, context=None):
 
209
        """Return all bank types when no payment_code is given (which is
 
210
        currently always the case when selecting invoices for payment orders.
 
211
        See " t = None " line in
 
212
        account_payment/wizard/account_payment_order.py.
 
213
        TODO: find the logical error for this and file bug report accordingly
 
214
        """
 
215
        if not payment_code:
 
216
            cr.execute(""" SELECT DISTINCT state FROM res_partner_bank """)
 
217
            return [x[0] for x in cr.fetchall()]
 
218
        return super(payment_mode, self).suitable_bank_types(
 
219
            cr, uid, payment_code, context)
 
220
 
 
221
 
 
222
    _columns = {
 
223
        'type': fields.many2one(
 
224
            'payment.mode.type', 'Payment type',
 
225
            help='Select the Payment Type for the Payment Mode.'
 
226
            ),
 
227
        }
 
228
payment_mode()
 
229
 
186
230
class account_bank_statement(osv.osv):
187
231
    '''
188
232
    Extensions from account_bank_statement:
264
308
    #    '''
265
309
    #    return None
266
310
 
267
 
    def button_confirm(self, cursor, uid, ids, context=None):
268
 
        '''
269
 
        Trigger function for button 'Confirm'
270
 
        As this function completely replaces the old one in account, other
271
 
        modules who wish to alter behavior of this function but want to
272
 
        cooperate with account_banking, should move their functionality to 
273
 
 
274
 
            on_button_confirm(self, cursor, uid, ids, context=None)
275
 
 
276
 
        and drop any calls to super() herein.
277
 
        In order to allow usage with and without account_banking, one could
278
 
        use 
279
 
 
280
 
            def on_button_confirm(...):
281
 
                # Your code here
282
 
 
283
 
            def button_confirm(...):
284
 
                super(my_class, self).button_confirm(...)
285
 
                self.on_button_confirm(...)
286
 
 
287
 
        This way, code duplication is minimized.
288
 
        '''
 
311
    def create_move_from_st_line(self, cr, uid, st_line_id,
 
312
                                 company_currency_id, st_line_number,
 
313
                                 context=None):
289
314
        # This is largely a copy of the original code in account
 
315
        # Modifications are marked with AB
290
316
        # As there is no valid inheritance mechanism for large actions, this
291
317
        # is the only option to add functionality to existing actions.
292
318
        # WARNING: when the original code changes, this trigger has to be
293
319
        # updated in sync.
294
 
        done = []
 
320
        if context is None:
 
321
            context = {}
295
322
        res_currency_obj = self.pool.get('res.currency')
296
 
        res_users_obj = self.pool.get('res.users')
297
323
        account_move_obj = self.pool.get('account.move')
298
324
        account_move_line_obj = self.pool.get('account.move.line')
299
 
        account_bank_statement_line_obj = \
300
 
                self.pool.get('account.bank.statement.line')
301
 
 
302
 
        company_currency_id = res_users_obj.browse(cursor, uid, uid,
303
 
                context=context).company_id.currency_id.id
304
 
 
305
 
        for st in self.browse(cursor, uid, ids, context):
306
 
            if not st.state=='draft':
307
 
                continue
308
 
 
309
 
            # Calculate statement balance from the contained lines
310
 
            end_bal = st.balance_end or 0.0
311
 
            if not (abs(end_bal - st.balance_end_real) < 0.0001):
 
325
        account_bank_statement_line_obj = self.pool.get(
 
326
            'account.bank.statement.line')
 
327
        st_line = account_bank_statement_line_obj.browse(cr, uid, st_line_id,
 
328
                                                         context=context)
 
329
        st = st_line.statement_id
 
330
 
 
331
        context.update({'date': st_line.date})
 
332
        period_id = self._get_period(
 
333
            cr, uid, st_line.date, context=context) # AB
 
334
 
 
335
        move_id = account_move_obj.create(cr, uid, {
 
336
            'journal_id': st.journal_id.id,
 
337
            'period_id': period_id, # AB
 
338
            'date': st_line.date,
 
339
            'name': st_line_number,
 
340
        }, context=context)
 
341
        account_bank_statement_line_obj.write(cr, uid, [st_line.id], {
 
342
            'move_ids': [(4, move_id, False)]
 
343
        })
 
344
 
 
345
        if st_line.amount >= 0:
 
346
            account_id = st.journal_id.default_credit_account_id.id
 
347
        else:
 
348
            account_id = st.journal_id.default_debit_account_id.id
 
349
 
 
350
        acc_cur = ((st_line.amount <= 0 and
 
351
                    st.journal_id.default_debit_account_id) or
 
352
                   st_line.account_id)
 
353
        context.update({
 
354
                'res.currency.compute.account': acc_cur,
 
355
            })
 
356
        amount = res_currency_obj.compute(cr, uid, st.currency.id,
 
357
                company_currency_id, st_line.amount, context=context)
 
358
 
 
359
        val = {
 
360
            'name': st_line.name,
 
361
            'date': st_line.date,
 
362
            'ref': st_line.ref,
 
363
            'move_id': move_id,
 
364
            'partner_id': (((st_line.partner_id) and st_line.partner_id.id) or
 
365
                           False),
 
366
            'account_id': (st_line.account_id) and st_line.account_id.id,
 
367
            'credit': ((amount>0) and amount) or 0.0,
 
368
            'debit': ((amount<0) and -amount) or 0.0,
 
369
            'statement_id': st.id,
 
370
            'journal_id': st.journal_id.id,
 
371
            'period_id': period_id, # AB
 
372
            'currency_id': st.currency.id,
 
373
            'analytic_account_id': (st_line.analytic_account_id and
 
374
                                    st_line.analytic_account_id.id or
 
375
                                    False),
 
376
        }
 
377
 
 
378
        if st.currency.id <> company_currency_id:
 
379
            amount_cur = res_currency_obj.compute(cr, uid, company_currency_id,
 
380
                        st.currency.id, amount, context=context)
 
381
            val['amount_currency'] = -amount_cur
 
382
 
 
383
        if (st_line.account_id and st_line.account_id.currency_id and
 
384
            st_line.account_id.currency_id.id <> company_currency_id):
 
385
            val['currency_id'] = st_line.account_id.currency_id.id
 
386
            amount_cur = res_currency_obj.compute(cr, uid, company_currency_id,
 
387
                    st_line.account_id.currency_id.id, amount, context=context)
 
388
            val['amount_currency'] = -amount_cur
 
389
 
 
390
        move_line_id = account_move_line_obj.create(
 
391
            cr, uid, val, context=context)
 
392
        torec = move_line_id
 
393
 
 
394
        # Fill the secondary amount/currency
 
395
        # if currency is not the same than the company
 
396
        amount_currency = False
 
397
        currency_id = False
 
398
        if st.currency.id <> company_currency_id:
 
399
            amount_currency = st_line.amount
 
400
            currency_id = st.currency.id
 
401
        account_move_line_obj.create(cr, uid, {
 
402
            'name': st_line.name,
 
403
            'date': st_line.date,
 
404
            'ref': st_line.ref,
 
405
            'move_id': move_id,
 
406
            'partner_id': (((st_line.partner_id) and st_line.partner_id.id) or
 
407
                           False),
 
408
            'account_id': account_id,
 
409
            'credit': ((amount < 0) and -amount) or 0.0,
 
410
            'debit': ((amount > 0) and amount) or 0.0,
 
411
            'statement_id': st.id,
 
412
            'journal_id': st.journal_id.id,
 
413
            'period_id': period_id, # AB
 
414
            'amount_currency': amount_currency,
 
415
            'currency_id': currency_id,
 
416
            }, context=context)
 
417
 
 
418
        for line in account_move_line_obj.browse(cr, uid, [x.id for x in
 
419
                account_move_obj.browse(cr, uid, move_id,
 
420
                    context=context).line_id],
 
421
                context=context):
 
422
            if line.state <> 'valid':
312
423
                raise osv.except_osv(_('Error !'),
313
 
                    _('The statement balance is incorrect !\n') +
314
 
                    _('The expected balance (%.2f) is different '
315
 
                      'than the computed one. (%.2f)') % (
316
 
                          st.balance_end_real, st.balance_end
317
 
                      ))
318
 
            if (not st.journal_id.default_credit_account_id) \
319
 
                    or (not st.journal_id.default_debit_account_id):
320
 
                raise osv.except_osv(_('Configration Error !'),
321
 
                    _('Please verify that an account is defined in the journal.'))
322
 
 
323
 
            for line in st.move_line_ids:
324
 
                if line.state != 'valid':
325
 
                    raise osv.except_osv(_('Error !'),
326
 
                        _('The account entries lines are not in valid state.'))
327
 
 
328
 
            for move in st.line_ids:
329
 
                context.update({'date':move.date})
330
 
                # Essence of the change is here...
331
 
                period_id = self._get_period(cursor, uid, move.date, context=context)
332
 
                move_id = account_move_obj.create(cursor, uid, {
333
 
                    'journal_id': st.journal_id.id,
334
 
                    # .. and here
335
 
                    'period_id': period_id,
336
 
                    'date': move.date,
337
 
                }, context=context)
338
 
                account_bank_statement_line_obj.write(cursor, uid, [move.id], {
339
 
                    'move_ids': [(4, move_id, False)]
340
 
                })
341
 
                if not move.amount:
342
 
                    continue
343
 
 
344
 
                torec = []
345
 
                if move.amount >= 0:
346
 
                    account_id = st.journal_id.default_credit_account_id.id
347
 
                else:
348
 
                    account_id = st.journal_id.default_debit_account_id.id
349
 
                acc_cur = ((move.amount<=0) and st.journal_id.default_debit_account_id) \
350
 
                          or move.account_id
351
 
                amount = res_currency_obj.compute(cursor, uid, st.currency.id,
352
 
                        company_currency_id, move.amount, context=context,
353
 
                        account=acc_cur)
354
 
                if move.reconcile_id and move.reconcile_id.line_new_ids:
355
 
                    for newline in move.reconcile_id.line_new_ids:
356
 
                        amount += newline.amount
357
 
 
358
 
                val = {
359
 
                    'name': move.name,
360
 
                    'date': move.date,
361
 
                    'ref': move.ref,
362
 
                    'move_id': move_id,
363
 
                    'partner_id': ((move.partner_id) and move.partner_id.id) or False,
364
 
                    'account_id': (move.account_id) and move.account_id.id,
365
 
                    'credit': ((amount>0) and amount) or 0.0,
366
 
                    'debit': ((amount<0) and -amount) or 0.0,
367
 
                    'statement_id': st.id,
368
 
                    'journal_id': st.journal_id.id,
369
 
                    'period_id': period_id,
370
 
                    'currency_id': st.currency.id,
371
 
                }
372
 
 
373
 
                amount = res_currency_obj.compute(cursor, uid, st.currency.id,
374
 
                        company_currency_id, move.amount, context=context,
375
 
                        account=acc_cur)
376
 
                if st.currency.id != company_currency_id:
377
 
                    amount_cur = res_currency_obj.compute(cr, uid, company_currency_id,
378
 
                                st.currency.id, amount, context=context,
379
 
                                account=acc_cur)
380
 
                    val['amount_currency'] = -amount_cur
381
 
 
382
 
                if move.account_id and move.account_id.currency_id and move.account_id.currency_id.id != company_currency_id:
383
 
                    val['currency_id'] = move.account_id.currency_id.id
384
 
                    amount_cur = res_currency_obj.compute(cursor, uid, company_currency_id,
385
 
                            move.account_id.currency_id.id, amount, context=context,
386
 
                            account=acc_cur)
387
 
                    val['amount_currency'] = -amount_cur
388
 
 
389
 
                torec.append(account_move_line_obj.create(cursor, uid, val , context=context))
390
 
 
391
 
                if move.reconcile_id and move.reconcile_id.line_new_ids:
392
 
                    for newline in move.reconcile_id.line_new_ids:
393
 
                        account_move_line_obj.create(cursor, uid, {
394
 
                            'name': newline.name or move.name,
395
 
                            'date': move.date,
396
 
                            'ref': move.ref,
397
 
                            'move_id': move_id,
398
 
                            'partner_id': ((move.partner_id) and move.partner_id.id) or False,
399
 
                            'account_id': (newline.account_id) and newline.account_id.id,
400
 
                            'debit': newline.amount>0 and newline.amount or 0.0,
401
 
                            'credit': newline.amount<0 and -newline.amount or 0.0,
402
 
                            'statement_id': st.id,
403
 
                            'journal_id': st.journal_id.id,
404
 
                            'period_id': period_id,
405
 
                        }, context=context)
406
 
 
407
 
                # Fill the secondary amount/currency
408
 
                # if currency is not the same than the company
409
 
                amount_currency = False
410
 
                currency_id = False
411
 
                if st.currency.id <> company_currency_id:
412
 
                    amount_currency = move.amount
413
 
                    currency_id = st.currency.id
414
 
 
415
 
                account_move_line_obj.create(cursor, uid, {
416
 
                    'name': move.name,
417
 
                    'date': move.date,
418
 
                    'ref': move.ref,
419
 
                    'move_id': move_id,
420
 
                    'partner_id': ((move.partner_id) and move.partner_id.id) or False,
421
 
                    'account_id': account_id,
422
 
                    'credit': ((amount < 0) and -amount) or 0.0,
423
 
                    'debit': ((amount > 0) and amount) or 0.0,
424
 
                    'statement_id': st.id,
425
 
                    'journal_id': st.journal_id.id,
426
 
                    'period_id': period_id,
427
 
                    'amount_currency': amount_currency,
428
 
                    'currency_id': currency_id,
429
 
                    }, context=context)
430
 
 
431
 
                for line in account_move_line_obj.browse(cursor, uid, [x.id for x in 
432
 
                        account_move_obj.browse(cursor, uid, move_id, context=context).line_id
433
 
                        ], context=context):
434
 
                    if line.state != 'valid':
435
 
                        raise osv.except_osv(
436
 
                            _('Error !'),
437
 
                            _('Account move line "%s" is not valid')
438
 
                            % line.name
439
 
                        )
440
 
 
441
 
                if move.reconcile_id and move.reconcile_id.line_ids:
442
 
                    ## Search if move has already a partial reconciliation
443
 
                    previous_partial = False
444
 
                    for line_reconcile_move in move.reconcile_id.line_ids:
445
 
                        if line_reconcile_move.reconcile_partial_id:
446
 
                            previous_partial = True
447
 
                            break
448
 
                    ##
449
 
                    torec += map(lambda x: x.id, move.reconcile_id.line_ids)
450
 
                    #try:
451
 
                    if abs(move.reconcile_amount-move.amount)<0.0001:
452
 
 
453
 
                        writeoff_acc_id = False
454
 
                        #There should only be one write-off account!
455
 
                        for entry in move.reconcile_id.line_new_ids:
456
 
                            writeoff_acc_id = entry.account_id.id
457
 
                            break
458
 
                        ## If we have already a partial reconciliation
459
 
                        ## We need to make a partial reconciliation
460
 
                        ## To add this amount to previous paid amount
461
 
                        if previous_partial:
462
 
                            account_move_line_obj.reconcile_partial(cr, uid, torec, 'statement', context)
463
 
                        ## If it's the first reconciliation, we do a full reconciliation as regular
464
 
                        else:
465
 
                            account_move_line_obj.reconcile(
466
 
                                cursor, uid, torec, 'statement',
467
 
                                writeoff_acc_id=writeoff_acc_id,
468
 
                                writeoff_period_id=st.period_id.id,
469
 
                                writeoff_journal_id=st.journal_id.id,
470
 
                                context=context
471
 
                            )
472
 
                    else:
473
 
                        account_move_line_obj.reconcile_partial(
474
 
                            cursor, uid, torec, 'statement', context
475
 
                        )
476
 
 
477
 
                if st.journal_id.entry_posted:
478
 
                    account_move_obj.write(cursor, uid, [move_id], {'state':'posted'})
479
 
            done.append(st.id)
480
 
        self.write(cursor, uid, done, {'state':'confirm'}, context=context)
481
 
 
482
 
        # Be nice to other modules as well, relay button_confirm calls to
483
 
        # on_button_confirm calls.
484
 
        for other in self._abf_others:
485
 
            if hasattr(other, 'on_button_confirm'):
486
 
                other.on_button_confirm(self, cursor, uid, ids, context=context)
487
 
 
488
 
        return True
 
424
                        _('Journal Item "%s" is not valid') % line.name)
 
425
 
 
426
        # Bank statements will not consider boolean on journal entry_posted
 
427
        account_move_obj.post(cr, uid, [move_id], context=context)
 
428
        
 
429
        """ 
 
430
        Account-banking:
 
431
        - Write stored reconcile_id
 
432
        - Pay invoices through workflow 
 
433
        """
 
434
        if st_line.reconcile_id:
 
435
            account_move_line_obj.write(cr, uid, [torec], {
 
436
                    'reconcile_id': st_line.reconcile_id.id }, context=context)
 
437
            for move_line in (st_line.reconcile_id.line_id or []) + (
 
438
                st_line.reconcile_id.line_partial_ids or []):
 
439
                netsvc.LocalService("workflow").trg_trigger(
 
440
                    uid, 'account.move.line', move_line.id, cr)
 
441
        """ End account-banking """
 
442
 
 
443
        return move_id
489
444
 
490
445
account_bank_statement()
491
446
 
563
518
    #            res[line.id] = 0.0
564
519
    #    return res
565
520
 
 
521
    def _get_invoice_id(self, cr, uid, ids, name, args, context=None):
 
522
        res = {}
 
523
        for st_line in self.browse(cr, uid, ids, context):
 
524
            res[st_line.id] = False
 
525
            for move_line in (st_line.reconcile_id and
 
526
                              (st_line.reconcile_id.line_id or []) +
 
527
                              (st_line.reconcile_id.line_partial_ids or []) or
 
528
                              []):
 
529
                if move_line.invoice:
 
530
                    res[st_line.id] = move_line.invoice.id
 
531
                    continue
 
532
        return res
 
533
 
566
534
    _columns = {
567
535
        # Redefines
568
 
        'amount': fields.float('Amount', readonly=True,
 
536
        'amount': fields.float('Amount', readonly=True, 
 
537
                            digits_compute=dp.get_precision('Account'),
569
538
                            states={'draft': [('readonly', False)]}),
570
539
        'ref': fields.char('Ref.', size=32, readonly=True,
571
540
                            states={'draft': [('readonly', False)]}),
595
564
                            required=False,
596
565
                            states={'confirm': [('readonly', True)]},
597
566
                            ),
 
567
        'reconcile_id': fields.many2one(
 
568
            'account.move.reconcile', 'Reconciliation', readonly=True
 
569
            ),
 
570
        'invoice_id': fields.function(
 
571
            _get_invoice_id, method=True, string='Linked Invoice',
 
572
            type='many2one', relation='account.invoice'
 
573
            ),
598
574
    }
599
575
 
600
576
    _defaults = {
603
579
        'currency': _get_currency,
604
580
    }
605
581
 
606
 
    def onchange_partner_id(self, cursor, uid, line_id, partner_id, type,
607
 
                            currency_id, context=None
608
 
                           ):
609
 
        '''
610
 
        Find default accounts when encoding statements by hand
611
 
        '''
612
 
        if not partner_id:
613
 
            return {}
614
 
 
615
 
        result = {}
616
 
        if not currency_id:
617
 
            users_obj = self.pool.get('res.users')
618
 
            currency_id = users_obj.browse(
619
 
                    cursor, uid, uid, context=context
620
 
                ).company_id.currency_id.id
621
 
        result['currency_id'] = currency_id
622
 
        
623
 
        partner_obj = self.pool.get('res.partner')
624
 
        partner = partner_obj.browse(cursor, uid, partner_id, context=context)
625
 
        if partner.supplier and not partner.customer:
626
 
            if partner.property_account_payable.id:
627
 
                result['account_id'] = partner.property_account_payable.id
628
 
            result['type'] = 'supplier'
629
 
        elif partner.customer and not partner.supplier:
630
 
            if partner.property_account_receivable.id:
631
 
                result['account_id'] =  partner.property_account_receivable.id
632
 
            result['type'] = 'customer'
633
 
 
634
 
        return result and {'value': result} or {}
635
 
 
636
582
account_bank_statement_line()
637
583
 
638
 
class payment_type(osv.osv):
639
 
    '''
640
 
    Make description field translatable #, add country context
641
 
    '''
642
 
    _inherit = 'payment.type'
643
 
    _columns = {
644
 
        'name': fields.char('Name', size=64, required=True, translate=True,
645
 
                            help='Payment Type'
646
 
                           ),
647
 
        #'country_id': fields.many2one('res.country', 'Country',
648
 
        #                    required=False,
649
 
        #                    help='Use this to limit this type to a specific country'
650
 
        #                   ),
651
 
    }
652
 
    #_defaults = {
653
 
    #    'country_id': lambda *a: False,
654
 
    #}
655
 
payment_type()
656
 
 
657
584
class payment_line(osv.osv):
658
585
    '''
659
586
    Add extra export_state and date_done fields; make destination bank account
813
740
    Enable extra states for payment exports
814
741
    '''
815
742
    _inherit = 'payment.order'
 
743
 
 
744
    def _get_id_proxy(self, cr, uid, ids, name, args, context=None):
 
745
        return dict([(id, id) for id in ids])
 
746
 
816
747
    _columns = {
817
 
        'date_planned': fields.date(
 
748
        #
 
749
        # 'id_proxy' is simply a reference to the resource's id
 
750
        # for the following reason:
 
751
        #
 
752
        # The GTK client 6.0 lacks necessary support for old style wizards.
 
753
        # It does not pass the resource's id if the wizard is called from
 
754
        # a button on a form.
 
755
        #
 
756
        # As a workaround, we pass the payment order id in the context
 
757
        # Evaluating 'id' in the context in the webclient on a form
 
758
        # in readonly mode dies with an error "Invalid Syntax", because 'id'
 
759
        # evaluates to "<built-in function id>" and the resource's field
 
760
        # values are not passed to eval in readonly mode at all.
 
761
        # See /addons/openerp/static/javascript/form.js line 308
 
762
        #
 
763
        # Evaluating any other variable in the webclient on a form in
 
764
        # readonly mode fails silently. That is actually ok, because the
 
765
        # webclient still supports passing the resource id when an old style
 
766
        # wizard is called.
 
767
        #
 
768
        # Therefore, if we want to pass the id in the context safely we have to
 
769
        # pass it under a different name.
 
770
        #
 
771
        'id_proxy': fields.function(
 
772
            _get_id_proxy, method=True, string='Copy ID', type='integer',
 
773
            store={
 
774
                'payment.order': (
 
775
                    lambda self,cr,uid,ids,c=None:ids, ['id'], 10)
 
776
                }
 
777
            ),
 
778
        'date_scheduled': fields.date(
818
779
            'Scheduled date if fixed',
819
780
            states={
820
781
                'sent': [('readonly', True)],
883
844
            ),
884
845
    }
885
846
 
 
847
    def launch_wizard(self, cr, uid, ids, context=None):
 
848
        """
 
849
        Search for a wizard to launch according to the type.
 
850
        If type is manual. just confirm the order.
 
851
        Previously (pre-v6) in account_payment/wizard/wizard_pay.py
 
852
        """
 
853
        result = {}
 
854
        obj_model = self.pool.get('ir.model.data')
 
855
        order = self.browse(cr, uid, ids[0], context)
 
856
        t = order.mode and order.mode.type.code or 'manual'
 
857
        res_id = False
 
858
        if t != 'manual':
 
859
            gw = self.get_wizard(t)
 
860
            if gw:
 
861
                module, wizard = gw
 
862
                wiz_id = obj_model._get_id(cr, uid, module, wizard)
 
863
                if wiz_id:
 
864
                    res_id = obj_model.read(
 
865
                        cr, uid, [wiz_id], ['res_id'])[0]['res_id']
 
866
        if res_id:
 
867
            result = self.pool.get('ir.actions.wizard').read(
 
868
                cr, uid, [res_id])[0]
 
869
        else:
 
870
            self.action_sent(cr, uid, ids, context)
 
871
        result['nodestroy'] = True
 
872
        return result
 
873
 
886
874
    def _write_payment_lines(self, cursor, uid, ids, **kwargs):
887
875
        '''
888
876
        ORM method for setting attributes of corresponding payment.line objects.
890
878
        to the absence of filters on writes and hence the requirement to
891
879
        filter on the client(=OpenERP server) side.
892
880
        '''
 
881
        if isinstance(ids, (int, long)):
 
882
            ids = [ids]
893
883
        payment_line_obj = self.pool.get('payment.line')
894
884
        line_ids = payment_line_obj.search(
895
885
            cursor, uid, [
911
901
        Set both self and payment lines to state 'sent'.
912
902
        '''
913
903
        self._write_payment_lines(cursor, uid, ids, export_state='sent')
914
 
        self.write(cursor, uid, ids, {'state': 'rejected'})
915
904
        wf_service = netsvc.LocalService('workflow')
916
905
        for id in ids:
917
906
            wf_service.trg_validate(uid, 'payment.order', id, 'sent', cursor)
922
911
        Set both self and payment lines to state 'rejected'.
923
912
        '''
924
913
        self._write_payment_lines(cursor, uid, ids, export_state='rejected')
925
 
        self.write(cursor, uid, ids, {'state': 'rejected'})
926
914
        wf_service = netsvc.LocalService('workflow')
927
915
        for id in ids:
928
 
            wf_service.trg_validate(uid, 'payment.order', id, 'rejected', cursor)
 
916
            wf_service.trg_validate(
 
917
                uid, 'payment.order', id, 'rejected', cursor)
929
918
        return True
930
919
 
931
920
    def set_done(self, cursor, uid, id, *args):
932
921
        '''
933
922
        Extend standard transition to update children as well.
934
923
        '''
935
 
        self._write_payment_lines(cursor, uid, [id],
 
924
        self._write_payment_lines(cursor, uid, id, 
936
925
                                  export_state='done',
937
926
                                  date_done=time.strftime('%Y-%m-%d')
938
927
                                 )
1188
1177
        elif partner_id:
1189
1178
            partner_obj = self.pool.get('res.partner')
1190
1179
            country = partner_obj.browse(cursor, uid, partner_id).country
1191
 
            country_ids = [country.id]
 
1180
            country_ids = country and [country.id] or []
1192
1181
        # 4. Without any of the above, take the country from the company of
1193
1182
        # the handling user
1194
1183
        if not country_ids:
1197
1186
                country = user.address_id.country_id
1198
1187
                country_ids = [country.id]
1199
1188
            else:
1200
 
                # Ok, tried everything, give up and leave it to the user
1201
 
                return warning(_('Insufficient data'),
1202
 
                               _('Insufficient data to select online '
1203
 
                                 'conversion database')
1204
 
                              )
1205
 
 
 
1189
                if (user.company_id and user.company_id.partner_id and
 
1190
                    user.company_id.partner_id.country):
 
1191
                    country_ids =  [user.company_id.partner_id.country.id]
 
1192
                else:
 
1193
                    # Ok, tried everything, give up and leave it to the user
 
1194
                    return warning(_('Insufficient data'),
 
1195
                                   _('Insufficient country information to ' 
 
1196
                                     'select online conversion database')
 
1197
                                   )
1206
1198
        result = {'value': values}
1207
1199
        # Complete data with online database when available
1208
1200
        if country.code in sepa.IBAN.countries:
1218
1210
                            info.bic or iban_acc.BIC_searchkey,
1219
1211
                            code = info.code, name = info.bank
1220
1212
                            )
1221
 
                        values['country_id'] = country_id or \
1222
 
                                               country_ids and country_ids[0] or \
1223
 
                                               False
 
1213
                        values['country_id'] = (
 
1214
                            country_id or country_ids and country_ids[0] or
 
1215
                            False)
1224
1216
                        values['bank'] = bank_id or False
1225
1217
                    else:
1226
1218
                        info = None
1227
1219
                if info is None:
1228
1220
                    result.update(warning(
1229
1221
                        _('Invalid data'),
1230
 
                        _('The account number appears to be invalid for %(country)s')
1231
 
                        % {'country': country.name}
 
1222
                        _('Could not verify the account number\'s validity '
 
1223
                          'for %(country)s') % {'country': country.name}
1232
1224
                    ))
1233
1225
            except NotImplementedError:
1234
1226
                if country.code in sepa.IBAN.countries:
1239
1231
                        values['acc_number'] = acc_number
1240
1232
                        result.update(warning(
1241
1233
                            _('Invalid format'),
1242
 
                            _('The account number has the wrong format for %(country)s')
1243
 
                            % {'country': country.name}
 
1234
                            _('The account number has the wrong format for '
 
1235
                              '%(country)s') % {'country': country.name}
1244
1236
                        ))
1245
1237
                else:
1246
1238
                    values['acc_number'] = acc_number