This question has been flagged
3 Replies
7139 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

Avatar
Discard
Best Answer

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.


Avatar
Discard
Best Answer

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!

Avatar
Discard
Author Best Answer

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
Avatar
Discard