[trunk] controllers form, bad contidion on save

Bug #668465 reported by Serge
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Odoo Web Client
In Progress
Low
OpenERP R&D Web Team

Bug Description

If you have a button, link with a action type url, when you press on button in NOT edit mode, original code launch a write,
Comment in code say "bypass save, for button action in non-editable view" but the condition is bad, and 2 else do same thing.

addons/openerp/controllers/form.py Class Form, Function save

Original code
        # bypass save, for button action in non-editable view
        if not (params.button and params.editable and params.id):
            proxy = rpc.RPCProxy(params.model)
            if not params.id:
                ctx = dict((params.context or {}), **rpc.session.context)
                id = proxy.create(data, ctx)
                params.ids = (params.ids or []) + [int(id)]
                params.id = int(id)
                params.count += 1
            else:
                ctx = utils.context_with_concurrency_info(params.context, params.concurrency_info)
                id = proxy.write([params.id], data, ctx)

        elif params.button and params.editable and params.id:
            proxy = rpc.RPCProxy(params.model)
            ctx = utils.context_with_concurrency_info(params.context, params.concurrency_info)
            id = proxy.write([params.id], data, ctx)

Fix: The fix do create if button, editable and no id in param, else do a write if button, editable and id in param

if params.button and params.editable and not params.id:
            proxy = rpc.RPCProxy(params.model)
            ctx = dict((params.context or {}), **rpc.session.context)
            id = proxy.create(data, ctx)
            params.ids = (params.ids or []) + [int(id)]
            params.id = int(id)
            params.count += 1
        elif params.button and params.editable and params.id:
            proxy = rpc.RPCProxy(params.model)
            ctx = utils.context_with_concurrency_info(params.context, params.concurrency_info)
            id = proxy.write([params.id], data, ctx)

Serge (sboivin)
description: updated
Revision history for this message
Serge (sboivin) wrote :

Previous patch have a bug and not simplified this one better and work fine

Do write and create only if we are in edit mode
Do create is no id submit else do a write

New patch

 if params.editable:
            if not params.id:
                proxy = rpc.RPCProxy(params.model)
                ctx = dict((params.context or {}), **rpc.session.context)
                id = proxy.create(data, ctx)
                params.ids = (params.ids or []) + [int(id)]
                params.id = int(id)
                params.count += 1
            else:
                proxy = rpc.RPCProxy(params.model)
                ctx = utils.context_with_concurrency_info(params.context, params.concurrency_info)
                id = proxy.write([params.id], data, ctx)

Revision history for this message
Serge (sboivin) wrote :

any next on this bug ???

because is not a good way to call a write method when user only click on link to open google map .... your code always do a write call editable or not editable ... look it ....this need to be improve

Changed in openobject-client-web:
assignee: nobody → OpenERP SA's Web Client R&D (openerp-dev-web)
importance: Undecided → Low
status: New → Confirmed
Revision history for this message
Sananaz (Open ERP) (sma-tiny) wrote :

Hello Serge,

Its fixed in trunk web-client. Please update your code.

Revision-info:
4095 <email address hidden>

Thanks.

Changed in openobject-client-web:
status: Confirmed → In Progress
status: In Progress → Fix Released
milestone: none → 6.0-rc2
Revision history for this message
Serge (sboivin) wrote :

i know i promise to not come here again, but i see a update today and i'm not realy agree with you

in the update now we CAN'T click on button if form is not in edit mode... you take the short way to solve the problem but is not the good one.

Imagine, we create a sale order, next day sales order is confirmed, we open the sale order, and try to confirm with button .. nothing because we are not in edit ... with the update we need to edit record to press a button, is not the best way, because we DONT need to edit the record so, no reason to press edit before press confirm order.

anyway i'm not sure is this update is your release because the messagein log is not clear. "[FIX] Fixed Button clicked for view mode. rev 4095"

Maybe you need to ask end user to know on this small change affect them, but i'm sure they will not be happy to need to press edit before press a button in a form view. I know is only a action (press a button) but end user never happy when you add one action to do.

The best way to correct this problem is allow press button in no editable state and NOT SAVE record when a button pressed in no editable state. i make all code for you before, i you no like it, change it but is the best way to correct it.

Serge (sboivin)
Changed in openobject-client-web:
status: Fix Released → New
Revision history for this message
Sananaz (Open ERP) (sma-tiny) wrote :

Hello Serge,

Sorry for my last commit. Now it fixed in trunk web-client.
Please update your code and notify us.

Revision-info:
4106 <email address hidden>

Thanks for notifying.

Changed in openobject-client-web:
status: New → Fix Released
Revision history for this message
Serge (sboivin) wrote :

i see the change, that look good, i will test it today and give you a feedback after

Revision history for this message
Serge (sboivin) wrote :

That work great, and code little more fast no save for nothing.

Thank a lot !!

Revision history for this message
Serge (sboivin) wrote :

Doh !!!

After this morning test i get a bug with this patch. If we are in EDITABLE mode we NEED a save (for wizard).

How to see the problem:

Create a wizard with 1 fields(field1), create 1 buttons.

write 'first press' in field, click button (print in debug self.datas[ids[0]]['field1'])

result, print 'first press'

write 'second press' in field, click button (print in debug self.datas[ids[0]]['field1'])

result, print 'first press'

Like you see, data not saved when we do second click, because now data have a id
(if (not(params.button) and params.editable) or not params.id:)
      not True and True or not True

So never save after the first use
So,
if (not(params.button) and params.editable) or not params.id:
Change by
if params.editable
(always save in editable mode)

Changed in openobject-client-web:
status: Fix Released → New
Changed in openobject-client-web:
status: New → In Progress
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.