Forum

Welcome to ProjeQtOr new Forum. We migrated old forum to the new website.
You will find all your posts here, with your usual account.
Just one point : you’ll have to reinitialize your password. Use “Lost password” feature.

Update and save a c...
 
Notifications
Clear all

Update and save a custom readonly field before object detail loads

5 Posts
2 Users
0 Reactions
3,958 Views
(@papjul)
Posts: 143
Active Member
Topic starter
 
[#2379]

Hi,

I created a custom Budget module (which I'm willing to share with the community once it works), with a readonly field "real amount" which is the sum of all invoices of a given project (to know the amount spent and compare with planned amount). Unfortunately, I don't understand how I can update and save this value.

What I would like to do:
1) Select a budget element in the list
2) Update and save its real amount by calculating all related invoices
3) Show the budget element in object detail with the updated value
4) Even if we don't make any modifications and don't save, the value is saved in database

Or better solution but I'm not sure it is possible: update all "real amount" columns when list of budget (in list area) is shown.

I tried to update value in the Budget constructor, but I can't use $this->save(), Budget isn't loading anymore. If I remove the $this->save() and I save manually the element, it says "No change to update" although the real amount field has changed.

I'm sure that's not a big deal but I keep looking and can't find how to do that. As you better know the application than me, do you know how I could achieve that?

Thank you,


 
Posted : 19 Jun 2015 18H05
(@babynus)
Posts: 14952
Member Admin
 

I think the way you try to do it is not the good one.
It's better to take the problem the other way round.

Change the save() method of the Bill object (corresponding to invoices), so that each time you save an invoce the corresponding budget is updated.
It is how is it done to sum up values from work, to assignments, to activities and to projects.
Have a look at PlanningElement object to see examples.


 
Posted : 19 Jun 2015 19H36
(@papjul)
Posts: 143
Active Member
Topic starter
 

Yes, I think of that way but I thought there would be too many cases to take into account (creation, update, delete, maybe other special cases I don't think of).
I will see when I get back to it in 2 weeks, thank you for your answer!


 
Posted : 20 Jun 2015 0H20
(@babynus)
Posts: 14952
Member Admin
 

Not so complex.

In Budget, add new public method : updateSynthesis (look in PlanningElement for example).
In Bill, on save() and deleted() (after parent::save() and parent::delete()), call updateSynthesis() for corresponding Budget.
That's all.


 
Posted : 20 Jun 2015 22H46
(@papjul)
Posts: 143
Active Member
Topic starter
 

Thanks, it worked (I had to add it to delete() in BillLine too).


 
Posted : 03 Jul 2015 10H54
Share:

Scroll to Top