267
def button_confirm(self, cursor, uid, ids, context=None):
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
274
on_button_confirm(self, cursor, uid, ids, context=None)
276
and drop any calls to super() herein.
277
In order to allow usage with and without account_banking, one could
280
def on_button_confirm(...):
283
def button_confirm(...):
284
super(my_class, self).button_confirm(...)
285
self.on_button_confirm(...)
287
This way, code duplication is minimized.
311
def create_move_from_st_line(self, cr, uid, st_line_id,
312
company_currency_id, st_line_number,
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.
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')
302
company_currency_id = res_users_obj.browse(cursor, uid, uid,
303
context=context).company_id.currency_id.id
305
for st in self.browse(cursor, uid, ids, context):
306
if not st.state=='draft':
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,
329
st = st_line.statement_id
331
context.update({'date': st_line.date})
332
period_id = self._get_period(
333
cr, uid, st_line.date, context=context) # AB
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,
341
account_bank_statement_line_obj.write(cr, uid, [st_line.id], {
342
'move_ids': [(4, move_id, False)]
345
if st_line.amount >= 0:
346
account_id = st.journal_id.default_credit_account_id.id
348
account_id = st.journal_id.default_debit_account_id.id
350
acc_cur = ((st_line.amount <= 0 and
351
st.journal_id.default_debit_account_id) or
354
'res.currency.compute.account': acc_cur,
356
amount = res_currency_obj.compute(cr, uid, st.currency.id,
357
company_currency_id, st_line.amount, context=context)
360
'name': st_line.name,
361
'date': st_line.date,
364
'partner_id': (((st_line.partner_id) and st_line.partner_id.id) or
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
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
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
390
move_line_id = account_move_line_obj.create(
391
cr, uid, val, context=context)
394
# Fill the secondary amount/currency
395
# if currency is not the same than the company
396
amount_currency = 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,
406
'partner_id': (((st_line.partner_id) and st_line.partner_id.id) or
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,
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],
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
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.'))
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.'))
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,
335
'period_id': period_id,
338
account_bank_statement_line_obj.write(cursor, uid, [move.id], {
339
'move_ids': [(4, move_id, False)]
346
account_id = st.journal_id.default_credit_account_id.id
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) \
351
amount = res_currency_obj.compute(cursor, uid, st.currency.id,
352
company_currency_id, move.amount, context=context,
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
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,
373
amount = res_currency_obj.compute(cursor, uid, st.currency.id,
374
company_currency_id, move.amount, context=context,
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,
380
val['amount_currency'] = -amount_cur
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,
387
val['amount_currency'] = -amount_cur
389
torec.append(account_move_line_obj.create(cursor, uid, val , context=context))
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,
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,
407
# Fill the secondary amount/currency
408
# if currency is not the same than the company
409
amount_currency = False
411
if st.currency.id <> company_currency_id:
412
amount_currency = move.amount
413
currency_id = st.currency.id
415
account_move_line_obj.create(cursor, uid, {
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,
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
434
if line.state != 'valid':
435
raise osv.except_osv(
437
_('Account move line "%s" is not valid')
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
449
torec += map(lambda x: x.id, move.reconcile_id.line_ids)
451
if abs(move.reconcile_amount-move.amount)<0.0001:
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
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
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
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,
473
account_move_line_obj.reconcile_partial(
474
cursor, uid, torec, 'statement', context
477
if st.journal_id.entry_posted:
478
account_move_obj.write(cursor, uid, [move_id], {'state':'posted'})
480
self.write(cursor, uid, done, {'state':'confirm'}, context=context)
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)
424
_('Journal Item "%s" is not valid') % line.name)
426
# Bank statements will not consider boolean on journal entry_posted
427
account_move_obj.post(cr, uid, [move_id], context=context)
431
- Write stored reconcile_id
432
- Pay invoices through workflow
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 """
490
445
account_bank_statement()