Crash general ledger report when account_move_line debit or credit is null

Bug #969357 reported by Alexis de Lattre
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Camptocamp Financial Addons
Opinion
High
Unassigned

Bug Description

I am using OpenERP 6.1 with the module account_financial_report_webkit from c2c-financial-addons/6.1.

I have experienced an issue when trying to print a Webkit General ledger report ; after a long debugging party, I eventually figured out that the root cause was some account_move_lines that had credit or debit = NULL instead of 0.00 in the SQL database. By the way, all the account move lines with debit or credit = NULL corresponded to payroll accout move lines which had been imported via extra-5.0/etl with a custom configuration developped by Tiny specifically for Anevia.

So, when you have such account move lines and you try to print a Webkit General ledger, you get this crash :

Traceback (most recent call last):
  File "/opt/openerp_bzr/trunk/ademeaulte/new/addons/account_financial_report_webkit/report/webkit_parser_header_fix.py", line 200, in create_single_pdf
    **self.parser_instance.localcontext)
  File "/usr/lib/pymodules/python2.6/mako/template.py", line 133, in render
    return runtime._render(self, self.callable_, args, data)
  File "/usr/lib/pymodules/python2.6/mako/runtime.py", line 364, in _render
    _render_context(template, callable_, context, *args, **_kwargs_for_callable(callable_, data))
  File "/usr/lib/pymodules/python2.6/mako/runtime.py", line 381, in _render_context
    _exec_template(inherit, lclcontext, args=args, kwargs=kwargs)
  File "/usr/lib/pymodules/python2.6/mako/runtime.py", line 414, in _exec_template
    callable_(context, *args, **kwargs)
  File "memory:0x1f33ea6c", line 188, in render_body
    ## balance cumulated
  File "/opt/openerp_bzr/trunk/ademeaulte/new/server-adl/openerp/report/report_sxw.py", line 315, in formatLang
    res = self.lang_dict['lang_obj'].format('%.' + str(digits) + 'f', value, grouping=grouping, monetary=monetary)
  File "/opt/openerp_bzr/trunk/ademeaulte/new/server-adl/openerp/osv/orm.py", line 368, in function_proxy
    return attr(self._cr, self._uid, [self._id], *args, **kwargs)
  File "/opt/openerp_bzr/trunk/ademeaulte/new/server-adl/openerp/addons/base/res/res_lang.py", line 207, in format
    formatted = percent % value
TypeError: float argument required, not NoneType

After some analysis, here is the scenario in the cash :

in account_financial_report_webkit/report/template/account_report_general_ledger.mako line 186/187, you have :

${ formatLang(line.get('debit', 0.0)) | amount }
${ formatLang(line.get('credit', 0.0)) | amount }

When the debit or credit field in the account_move_line is NULL, you have :

line.get('debit', 0.0)=None.

So it calls the formatLang() function located in server/openerp/report/report_sxw.py with value = None, and it eventually crashes in server/openerp/addons/base/res/res_lang.py

In order to solve the issue, I applied the following SQL patch :

update account_move_line set debit=0.0 where debit is null;
update account_move_line set credit=0.0 where credit is null;

I don't know who is to blame for this issue :
1. should the report convert None value to 0.0 ?
2. should the server handle this ?
3. is it the fault of my bad data, i.e. the debit and credit fields of account_move_line should never contain NULL value ?

If you think that the culprit is 2 or 3, you can just mark my bug as invalid. At least, it will be referenced in Google and the users who face the same crash will be able to easily find the solution... it will avoid them a long debugging party !

Changed in c2c-financial-addons:
status: New → Confirmed
importance: Undecided → High
Changed in c2c-financial-addons:
status: Confirmed → Opinion
Revision history for this message
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote :

Hello,

OpenERP never puts null values in float fields, like debit or credit. So I'm not sure the reports have to cover this corner case.

Thanks Alexis for this detailed report.

Guewen

Revision history for this message
YannickB (YOLO consulting) (yannick-buron) wrote :

I had the same error.

Thanks to your information, I was able to see that for some records the column debit or credit was at NULL instead of "0.00". So I was able to correct the problem by correcting the data.

I have no idea how this happens, maybe because of a big computation we brutally stopped one day. Still, I think we have to be carefull, maybe OpenERP isn't reliable enough about this "always at 0.00 in db if NULL" rule.

Revision history for this message
Alexis de Lattre (alexis-via) wrote :

@YannickB My bug report was specifically designed to be indexed in Google so that other users with the same problem can fix their data with the SQL request I gave. I am glad that it was usefull for you ! :)

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.