Trigger on store function field doesn't work in inherits object

Bug #704922 reported by Joël Grand-Guillaume @ camptocamp
68
This bug affects 10 people
Affects Status Importance Assigned to Milestone
Odoo Server (MOVED TO GITHUB)
Fix Released
Medium
OpenERP Publisher's Warranty Team

Bug Description

Hi,

This is a quite complex one affecting last v6.0 :( Also to explain, I'll try...

Situation :

- Add a store field on account.analytic.line with the following:

'aa_currency_id': fields.function(_get_account_currency, method=True, type='many2one', relation='res.currency', string='Account currency',
                  store={
                      'account.analytic.account': (_get_account_line, ['company_id'], 50),
                      'account.analytic.line': (lambda self,cr,uid,ids,c={}: ids, ['amount','unit_amount'],10),
                  },
                  help="The related analytic account currency."),

- This will trigger any modifications done on the related analytic account or in the amount or unit_amount field of analytic lines. When the trigger is trigged, the value of aa_curency_id is re-computed by _get_account_currency.

This works perfectly as expected, the trigger works. But then you install hr_timesheet module which inherits account.analytic.line and try to change something in the hr.analytic.timesheet, the trigger on the account.analytic.line isn't trigged !!!

You can find a working example in the c2c_multicost_base module of extra-addons for v 5.0, in v5.0 this works perfectly. Changing the hr.analytic.timesheet will trig the account.analytic.line.

I expect this to work also n v 6.0. A trigger put on an object A should be trigged also when an inherits object B change some values in the inherited object A.

Thanks to have a look, this sould be very important I think.

Regards,

Joël

summary: - Trigger on store field doesn't work inherits object
+ Trigger on store function field doesn't work in inherits object
Revision history for this message
Joël Grand-Guillaume @ camptocamp (jgrandguillaume-c2c) wrote :

I just push the "analytic_multicurrency" module that provide this store function field, you can easily try to reproduc this bug by installing it on your system. Available in the extra-addons branch of the trunk v6.0

Revision history for this message
Azazahmed Saiyed (OpenERP) (saz-openerp) wrote :

Hello,

I have checked the issue in stable 6.0 with the following steps:

First installed the module suggested by you i.e "analytic_multicurrency" and then also installed the hr_timesheet_sheet module where account.analytic.line has been inherited.

Check with the modification in existing fields of analytic lines as well as created a new line and it triggers the both function field of the "analytic_multicurrency" module and working good.

Please notify me If I did misunderstand the bug specification for reproducing it. So need more information from your side and waiting for your reply.

Thanks.

Changed in openobject-server:
status: New → Incomplete
Revision history for this message
Joël Grand-Guillaume @ camptocamp (jgrandguillaume-c2c) wrote :

Hi,

First of all thank you to have a look on that one ! I just updated to today version and it seems I always have this trouble... According to my test case:

1) Install basic OpenERP with analytic_multicurrency, hr_timesheet & hr_timesheet_sheet

2) Create a line from menu : Accounting -> Journal Entries -> Analytic Journal Items => You can see the second "Amount Currency" in form view computed right (in my case 10 hours at 30 EUR = 300 EUR).

3) The same but from menu : Human Ressources -> Time Tracking -> Working Hours => You can also see the second "Amount Currency computed right.

4) When you try from Human Ressources -> Time Tracking -> My Timesheet and encode a line here, everything is fine unless you check that line from the menu of point 2).

So if you take the menu described in 2) to verify the line entered from "My Timesheet", you'll see the "Amount Currency" function field empty :(

This is may be because of 2 inherit : first one hr.analytic.line inherits account.analytic.line. And in hr_timesheet_sheet, you inherit hr.analytic.line once more... But well, even looking at the code closely, I cannot understand that...

Hope this help.

Regards,

Joël

Changed in openobject-server:
status: Incomplete → New
Revision history for this message
Azazahmed Saiyed (OpenERP) (saz-openerp) wrote :

Hello Joel,

Thanks for giving the detailed information for reproducing the bug. It seems to be problem in store function field when we are checking it with the inherited object. So I am confirming this bug.

Thanks.

Changed in openobject-server:
assignee: nobody → OpenERP's Framework R&D (openerp-dev-framework)
importance: Undecided → Medium
status: New → Confirmed
Changed in openobject-server:
status: Confirmed → In Progress
Changed in openobject-server:
status: In Progress → Confirmed
Revision history for this message
Albert Cervera i Areny - http://www.NaN-tic.com (albert-nan) wrote :

The bug is in function orm's __init__() function and also fails to consider the case when a function or related field is inherited and replaced by a "normal" field. The reason is that the function fills in a dictionary in the pool called _store_function but entries in the dictionary are not removed when a function field is inherited.

The attached patch fixes that by removing those entries (if they exist). It creates a new "_store_function_inv" dictionary to speed up the search. It seems to work properly in my case. Joël, can you give it a try?

Revision history for this message
Joël Grand-Guillaume @ camptocamp (jgrandguillaume-c2c) wrote :

Hi Albert,

Your fix seems to make things right on the modification of an inherited object. Like:

Modifying hr.analytic.timesheet values, trigger right the function field defined on account.analytic.line.

But unfortunately, this work only on modification. Creating an hr.analytic.timesheet still don't trigger the function field of account.analytic.line :(

Anyway, thanks to solve half of it !

Regards,

Joël

Revision history for this message
Ferdinand (office-chricar) wrote :

just was hitting the same bug
see attached module for testing

this will give pretty unpredictable results if not fixed ASAP

Revision history for this message
Cristian Salamea (ovnicraft) wrote :

Hello i found some problems in my module with this bug and i need fixed it, when OpenERP start the fixed or will apply the Albert's patch?

Regards,

Revision history for this message
Nicolas Clavier (nicoclavier) wrote :

Hi folks,

I seem to be facing this exact bug in version 6.0.2 of the server.

It happens on a custom module in which I extend :
- project.project to add some fields
- account.analytic.account (inherited by delegation in project.project ) , to override the name field of account.analytic.account to become a function field.

I patch orm.py & osv.py as per the diff file attached above.
=> on creation of record the function of account.analytic.account name field does not trigger
=> it does trigger the function (observed by logging), but the value is not stored, nor returned to the views.

Since this bug is still open, my question is :
- how do you folks manage to work with triggers on functions field in inherited classes ?

This fix is vital to me, but probably urgent for the openobject project altogether.

Regards,
Nicolas

Changed in openobject-server:
assignee: OpenERP's Framework R&D (openerp-dev-framework) → OpenERP Publisher's Warranty Team (openerp-opw)
tags: added: maintenance
removed: nan
Revision history for this message
Ferdinand (office-chricar) wrote :

please can we get an update on this very annoying bug

Revision history for this message
Paulius Sladkevičius @ hbee (komsas) wrote :

This still exist on the server trunk #4080 rev., any possibilities to solve it?

To reproduce:
- Inherit account.invoice with "class inheritance" f.e. account.test;
- Try to create new invoice.

You'll get error something like "'Field move_id not found in browse_record(account.test, 23)"

Revision history for this message
Olivier Dony (Odoo) (odo-openerp) wrote :

A fix for this issue has landed in the server branch of the 6.1 series [1]. It should be available tomorrow in the nightly builds, and will be merged in trunk (for 7.0) along with the next batch of forward-ports.

I've tried Joel's testcase (comment #3) before and after the patch, and it seems to fix it properly.

Thanks for reporting with a detailed test case, this was not an easy one to diagnose!

[1] server 6.1 rev.4193 revision-id: <email address hidden>

Changed in openobject-server:
milestone: none → 6.1
status: Confirmed → Fix Released
tags: added: needs-test
Revision history for this message
Nicolas Clavier (nicoclavier) wrote :

Hi & thanks Olivier,

Is there any chance to see a back port of this fix in the 6.0 series ? Since there are quite some developments still going on under v6.0x ..?

Nicolas

Revision history for this message
Olivier Dony (Odoo) (odo-openerp) wrote : Re: [Bug 704922] Re: Trigger on store function field doesn't work in inherits object

On 06/04/2012 04:10 PM, Nicolas Clavier wrote:
> Is there any chance to see a back port of this fix in the 6.0 series ?
> Since there are quite some developments still going on under v6.0x ..?

Yes, it was backported to 6.0 as well, at revision 3623 (revision-id:
<email address hidden>).

Revision history for this message
Nicolas Clavier (nicoclavier) wrote :

Wonderful ! Thank you.

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

Duplicates of this bug

Other bug subscribers

Remote bug watches

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