Se rendre au contenu
Menu
Cette question a été signalée
3 Réponses
7900 Vues

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
Ignorer
Meilleure réponse

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
Ignorer
Meilleure réponse

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
Ignorer
Auteur Meilleure réponse

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
Ignorer
Publications associées Réponses Vues Activité
0
sept. 23
1563
0
sept. 23
1318
2
févr. 23
10604
6
oct. 23
21343
3
mars 24
8921