Validating a Bank Statement with centralized option in bank journal crashes

Bug #997316 reported by TeMPO
16
This bug affects 3 people
Affects Status Importance Assigned to Milestone
Odoo Addons (MOVED TO GITHUB)
Fix Released
Medium
OpenERP R&D Addons Team 3
OpenERP Community Backports (Addons)
New
Undecided
Unassigned
6.1
Fix Released
Medium
Unassigned

Bug Description

6.1

Setup a demo database
Change the setting of bank journal and check the tickbox "Centralised Counterpart"
Make a bank statement with two lines and validate it
System crashes with following message

Server Traceback (most recent call last):
  File "/home/tempo/openerp-6.1-1/openerp/addons/web/common/http.py", line 592, in send
    result = openerp.netsvc.dispatch_rpc(service_name, method, args)
  File "/home/tempo/openerp-6.1-1/openerp/netsvc.py", line 360, in dispatch_rpc
    result = ExportService.getService(service_name).dispatch(method, params)
  File "/home/tempo/openerp-6.1-1/openerp/service/web_services.py", line 572, in dispatch
    res = fn(db, uid, *params)
  File "/home/tempo/openerp-6.1-1/openerp/osv/osv.py", line 167, in execute_kw
    return self.execute(db, uid, obj, method, *args, **kw or {})
  File "/home/tempo/openerp-6.1-1/openerp/osv/osv.py", line 121, in wrapper
    return f(self, dbname, *args, **kwargs)
  File "/home/tempo/openerp-6.1-1/openerp/osv/osv.py", line 176, in execute
    res = self.execute_cr(cr, uid, obj, method, *args, **kw)
  File "/home/tempo/openerp-6.1-1/openerp/osv/osv.py", line 164, in execute_cr
    return getattr(object, method)(cr, uid, *args, **kw)
  File "/home/tempo/openerp-6.1-1/openerp/addons/account/account_bank_statement.py", line 361, in button_confirm_bank
    self.create_move_from_st_line(cr, uid, st_line.id, company_currency_id, st_line_number, context)
  File "/home/tempo/openerp-6.1-1/openerp/addons/account_voucher/account_voucher.py", line 1436, in create_move_from_st_line
    return super(account_bank_statement, self).create_move_from_st_line(cr, uid, st_line.id, company_currency_id, next_number, context=context)
  File "/home/tempo/openerp-6.1-1/openerp/addons/account/account_bank_statement.py", line 270, in create_move_from_st_line
    move_line_id = account_move_line_obj.create(cr, uid, val, context=context)
  File "/home/tempo/openerp-6.1-1/openerp/addons/account/account_move_line.py", line 1371, in create
    tmp = move_obj.validate(cr, uid, [vals['move_id']], context)
  File "/home/tempo/openerp-6.1-1/openerp/addons/account/account.py", line 1624, in validate
    self._centralise(cr, uid, move, 'debit', context=context)
  File "/home/tempo/openerp-6.1-1/openerp/addons/account/account.py", line 1500, in _centralise
    }, context)
  File "/home/tempo/openerp-6.1-1/openerp/addons/account/account_move_line.py", line 1371, in create
    tmp = move_obj.validate(cr, uid, [vals['move_id']], context)
  File "/home/tempo/openerp-6.1-1/openerp/addons/account/account.py", line 1624, in validate
    self._centralise(cr, uid, move, 'debit', context=context)
  File "/home/tempo/openerp-6.1-1/openerp/addons/account/account.py", line 1519, in _centralise
    if not currency_obj.is_zero(cr, uid, currency_id, row['amount_currency']):
  File "/home/tempo/openerp-6.1-1/openerp/addons/base/res/res_currency.py", line 172, in is_zero
    return float_is_zero(amount, precision_rounding=currency.rounding)
  File "/home/tempo/openerp-6.1-1/openerp/tools/float_utils.py", line 97, in float_is_zero
    return abs(float_round(value, precision_rounding=epsilon)) < epsilon
  File "/home/tempo/openerp-6.1-1/openerp/tools/float_utils.py", line 66, in float_round
    normalized_value = value / rounding_factor # normalize
TypeError: unsupported operand type(s) for /: 'NoneType' and 'float'

Related branches

Changed in openobject-addons:
status: New → Confirmed
importance: Undecided → Medium
assignee: nobody → OpenERP R&D Addons Team 3 (openerp-dev-addons3)
Changed in openobject-addons:
status: Confirmed → In Progress
Revision history for this message
Mayur Maheshwari(OpenERP) (mma-openerp) wrote :

Hello Tempo,

Thanks for Reporting.
It has been fixed in lp:~openerp-dev/openobject-addons/trunk-bug-997316-mma
Revision ID: <email address hidden>
Revision num: 6783

It will be available in trunk soon.

Changed in openobject-addons:
status: In Progress → Fix Committed
Revision history for this message
TeMPO (info-tempo-consulting) wrote :

Dear Mayur

I tried the fix, no crash anymore but I get an error message anyway

Error occurred while validating the field(s) journal_id: You can not create more than one move per period on centralized journal

But I've absolutely no line already created

Changed in openobject-addons:
status: Fix Committed → In Progress
Changed in openobject-addons:
status: In Progress → New
Revision history for this message
TeMPO (info-tempo-consulting) wrote :

Sorry but ignore my last comment since this was a bad configuration

Changed in openobject-addons:
status: New → Fix Committed
Revision history for this message
Fabien (Open ERP) (fp-tinyerp) wrote :

merged in trunk, v7.0

Changed in openobject-addons:
status: Fix Committed → Fix Released
Revision history for this message
Ronald Portier (Therp) (rportier1962) wrote :
Download full text (3.6 KiB)

The bug can also occur when generating a new opening balance. The main problem is that the selection for currency accounts can result in records with a not null currency, but a null amount.

The solution is to change the selection in account.py (lines may have changed):

1526 #adjust also the amount in currency if needed
1527 cr.execute("select currency_id, sum(amount_currency) as amount_currency from account_move_line where move_id = %s and currency_id is not null and amount_currency is not null group by currency_id", (move.id,))
1528 for row in cr.dictfetchall():
1529 currency_id = currency_obj.browse(cr, uid, row['currency_id'], context=context)
1530 if not currency_obj.is_zero(cr, uid, currency_id, row['amount_currency']):
1531 amount_currency = row['amount_currency'] * -1

In the above fragment I added " and amount_currency is not null" to line 1527. I will create a merge request for 6.1. maybe later for 7.0 as I think it will have the same problems.

Crash report:

Server Traceback (most recent call last):

  File "/home/oerttrprd61/openerp-web/addons/web/common/http.py", line
593, in send

    return openerp.netsvc.dispatch_rpc(service_name, method, args)

  File "/home/oerttrprd61/bzr/openobject-server/openerp/netsvc.py", line
360, in dispatch_rpc

    result = ExportService.getService(service_name).dispatch(method, params)

  File
"/home/oerttrprd61/bzr/openobject-server/openerp/service/web_services.py",
line 586, in dispatch

    res = fn(db, uid, *params)

  File "/home/oerttrprd61/bzr/openobject-server/openerp/osv/osv.py",
line 186, in execute_kw

    return self.execute(db, uid, obj, method, *args, **kw or {})

  File "/home/oerttrprd61/bzr/openobject-server/openerp/osv/osv.py",
line 129, in wrapper

    return f(self, dbname, *args, **kwargs)

  File "/home/oerttrprd61/bzr/openobject-server/openerp/osv/osv.py",
line 195, in execute

    res = self.execute_cr(cr, uid, obj, method, *args, **kw)

  File "/home/oerttrprd61/bzr/openobject-server/openerp/osv/osv.py",
line 183, in execute_cr

    return getattr(object, method)(cr, uid, *args, **kw)

  File
"/home/oerttrprd61/openobject-addons/account/wizard/account_fiscalyear_close.py",
line 256, in data_save

    obj_acc_move.validate(cr, uid, [move_id], context=context)

  File "/home/oerttrprd61/openobject-addons/account/account.py", line
1635, in validate

    self._centralise(cr, uid, move, 'debit', context=context)

  File "/home/oerttrprd61/openobject-addons/account/account.py", line
1511, in _centralise

    }, context)

  File
"/home/oerttrprd61/openobject-addons/account/account_move_line.py", line
1395, in create

    tmp = move_obj.validate(cr, uid, [vals['move_id']], context)

  File "/home/oerttrprd61/openobject-addons/account/account.py", line
1635, in validate

    self._centralise(cr, uid, move, 'debit', context=context)

  File "/home/oerttrprd61/openobject-addons/account/account.py", line
1530, in _centralise

    if not currency_obj.is_zero(cr, uid, currency_id,
row['amount_currency']):

  File
"/home/oerttrprd61/bzr/openobject-server/openerp/addons/base/res/res_currency.py",
line 172, in is_zero
...

Read more...

Revision history for this message
Stefan Rijnhart (Opener) (stefan-opener) wrote :

Hi Ronald,

if it's a different backtrace then it is probably a different bug, especially because this bug is fixed released and apparently tested and accepted by the original bug poster.

With regard to your issue, these move lines that set currency_id regardless of whether it is equal to the company currency are created in account/account_bank_statement.py. I wonder if this should be allowed at all. It is assumed that the move line's amount_currency is filled whenever currency_id is in other places as well, for instance here:
http://bazaar.launchpad.net/~openerp/openobject-addons/7.0/view/head:/account/account_move_line.py#L134

So the real bug may be that currency_id is set to company_currency, and amount_currency is not set.

Revision history for this message
Ronald Portier (Therp) (rportier1962) wrote :

Hello Stefan,

The significant part of the backtrace is starting from the _centralize
call. No difference with the original bug in what I encountered.

I agree with you that having a currency the same as the company currency
here is wrong. As are all instances of currency_id filled (= not null)
en amount_currency not filled (null).

But given the fact that both currency_id and amount_currency are null
capable, one way or another this situation can occur in the database,
and the _centralize code should be protected from this.

Of course the places in the code where these values are introduced into
the database are bugs in their own right.

Kind regards, Ronald

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.