Tryton - Issues

 

Issue7687

Title couldn't delete statement with lines
Priority bug Status resolved
Superseder Nosy List ced, pokoli, reviewbot, roundup-bot, semarie
Type crash Components account_statement
Assigned To pokoli Keywords review
Reviews 49561002
View: 49561002

Created on 2018-09-10.06:46:44 by semarie, last changed by roundup-bot.

Messages
New changeset 962997a5359f by Sergi Almacellas Abellana in branch '4.8':
Test if move is set before reading its lines
https://hg.tryton.org/modules/account_statement/rev/962997a5359f

New changeset 5bb6711eebfb by Sergi Almacellas Abellana in branch '4.6':
Test if move is set before reading its lines
https://hg.tryton.org/modules/account_statement/rev/5bb6711eebfb
New changeset 50116d7cf90d by Sergi Almacellas Abellana in branch 'default':
Test if move is set before reading its lines
https://hg.tryton.org/tryton-env/rev/50116d7cf90d
New changeset 3d7e57dc55be by Sergi Almacellas Abellana in branch 'default':
Test if move is set before reading its lines
https://hg.tryton.org/modules/account_statement/rev/3d7e57dc55be
review49561002 updated at https://codereview.tryton.org/49561002/#ps20001
msg43779 (view) Author: [hidden] (ced) (Tryton committer) (Tryton translator) Date: 2018-09-10.09:36:12
I agree keeping the list comprehension makes sense and is probably more efficient.
msg43777 (view) Author: [hidden] (semarie) Date: 2018-09-10.09:28:32
hep, it fixes it.

if you want to keep list comprehension, I think spliting/reordering the `if` clause should do the trick:

diff -r 7de89d79245e statement.py
--- a/statement.py      Sun Sep 09 10:08:22 2018 +0200
+++ b/statement.py      Mon Sep 10 09:21:50 2018 +0200
@@ -838,8 +838,8 @@
         Reconciliation = pool.get('account.move.reconciliation')

         reconciliations = [l.reconciliation
-            for line in lines for l in line.move.lines
-            if line.move and l.reconciliation]
+            for line in lines if line.move
+            for l in line.move.lines if l.reconciliation]
         Reconciliation.delete(reconciliations)
         Move.delete(list({l.move for l in lines if l.move}))

it fixes my usecase, but I am not confident enought in my python skill to be sure to be right in all cases.
review49561002 updated at https://codereview.tryton.org/49561002/#ps1
msg43775 (view) Author: [hidden] (pokoli) (Tryton committer) (Tryton translator) Date: 2018-09-10.09:14:15
Here is review49561002 that should fix it. Could you please test it?
msg43772 (view) Author: [hidden] (semarie) Date: 2018-09-10.06:46:43
If I try to delete a statement (in 'draft' state) whereas some lines were already filled, I have the following exception:

Traceback (most recent call last):
  File "/trytond/wsgi.py", line 73, in dispatch_request
    return endpoint(request, **request.view_args)
  File "/trytond/protocols/dispatcher.py", line 46, in rpc
    request, database_name, *request.rpc_params)
  File "/trytond/wsgi.py", line 44, in auth_required
    return wrapped(*args, **kwargs)
  File "/trytond/protocols/wrappers.py", line 122, in wrapper
    return func(request, pool, *args, **kwargs)
  File "/trytond/protocols/dispatcher.py", line 176, in _dispatch
    result = rpc.result(meth(*c_args, **c_kwargs))
  File "/trytond/modules/account_statement/statement.py", line 372, in delete
    cls.cancel(statements)
  File "/trytond/model/modelview.py", line 666, in wrapper
    return func(cls, records, *args, **kwargs)
  File "/trytond/model/workflow.py", line 36, in wrapper
    result = func(cls, filtered, *args, **kwargs)
  File "/trytond/modules/account_statement/statement.py", line 555, in cancel
    StatementLine.delete_move(lines)
  File "/trytond/modules/account_statement/statement.py", line 841, in delete_move
    for line in lines for l in line.move.lines
  File "/trytond/modules/account_statement/statement.py", line 841, in <listcomp>
    for line in lines for l in line.move.lines
AttributeError: 'NoneType' object has no attribute 'lines'

Please note that manually delete the lines, save the record, and next delete the statement works as excepted.

To reproduce:
- create a new Statement (with amount validation for example)
- add a StatementLine
- save the record
- delete the record : the exception is triggered
History
Date User Action Args
2018-10-02 13:07:47roundup-botsetmessages: + msg44267
2018-09-17 09:46:58roundup-botsetmessages: + msg43915
2018-09-17 09:46:53roundup-botsetstatus: testing -> resolved
nosy: + roundup-bot
messages: + msg43914
2018-09-10 09:55:08reviewbotsetmessages: + msg43781
2018-09-10 09:36:12cedsetnosy: + ced
messages: + msg43779
2018-09-10 09:28:33semariesetmessages: + msg43777
2018-09-10 09:26:07reviewbotsetnosy: + reviewbot
messages: + msg43776
2018-09-10 09:14:20pokolisetstatus: chatting -> testing
2018-09-10 09:14:16pokolisetstatus: unread -> chatting
keyword: + review
nosy: + pokoli
messages: + msg43775
reviews: 49561002
assignedto: pokoli
2018-09-10 06:46:44semariecreate

Showing 10 items. Show all history (warning: this could be VERY long)