Odoo Help

0

how to add smart button to calculate total aides

By
soumaya
on 6/9/16, 10:51 AM 963 views

Hi ,i am trying to add a smart button to my view which calculates the sum of total aides donated to a person this is  a part of the codeperson.py

def _aide_total(self, cr, uid, ids, field_name, arg, context=None):

res = {}

for aide in self.person_aide_ids.browse(cr, uid, ids, context=context):

total = 0.0

for line in aide.person_aide_valeur:

total += line.person_aide_valeur

res[aide.id] = total

return res

_name='person'

columns={

                 'person_aide_ids':fields.one2many('person.aide', 'person_id', 'المساعدات', required=False),

                 'total_person_aides': fields.function(_aide_total,string="القيمة الجملية للمساعدات", type='float'),

}

aide.py

        'person_aide_valeur':fields.float('قيمة المساعدة'),

person.xml:(only the button code)

<button type="action" class="oe_stat_button" icon="fa-pencil-square-o" name="المساعدات">

<field name="total_person_aides" string="المساعدات" widget="statinfo"/>

</button>


The button did not work
Can any one help me  
and thinks

3

Hi,

Just make changes inside your button with type=object and also make changes according to the following inside your function of that field.

def _aide_total(self, cr, uid, ids, field_name, arg, context=None):
res = {}
for obj in self.browse(cr, uid, ids, context=context):
total = 0.0
for line in obj.person_aide.ids:
total += line.person_aide_valeur
res[aide.id] = total
return res

I am sure that you will get value inside that function field as you want.


1
Pawan
On 6/10/16, 1:25 AM

soumaya,

Here in button type, u have 'action', which is used to call an xml action on it button click..

<button type="action" class="oe_stat_button" icon="fa-pencil-square-o" name="المساعدات">

So if u want to call server side(python) code, then keep type as 'object' ..

<button type="object" class="oe_stat_button" icon="fa-pencil-square-o" name="المساعدات">

Hope this will help you!

0
soumaya
On 6/10/16, 2:52 AM

thinks a lot Pawan and Emipro technologies 
with this code it works with the changes in the xml as Pawan said

def _aide_total(self, cr, uid, ids, field_name, arg, context=None):  
 res = {}
 for obj in self.browse(cr, uid, ids, context=context):
 total = 0.0 for line in obj.person_aide_ids:
 total += line.person_aide_valeur
 res[obj.id] = total return res

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)

Stats

Asked: 6/9/16, 10:51 AM
Seen: 963 times
Last updated: 6/10/16, 2:52 AM