Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
3 Trả lời
8108 Lượt xem

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

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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.


Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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!

Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

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
Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 9 23
2029
0
thg 9 23
1734
2
thg 6 25
11251
6
thg 10 23
22094
3
thg 3 24
9530