Odoo Help

Welcome!

This community 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.

0

how to add smart button to calculate total aides

By
soumaya
on 6/9/16, 10:51 AM 314 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

Emipro Technologies Pvt. Ltd.

--Emipro Technologies Pvt. Ltd.--
Tiny ERP Pvt Ltd
http://www.odoo.com
5975
| 6 7 8
Rajkot, India
--Emipro Technologies Pvt. Ltd.--

Being an emerging leader in IT market since 2011, Emipro Technologies Pvt. Ltd. has been providing a wide range of business solutions in Odoo & Magento. We are pleased to have a large pool of contented customers with our meticulous work in the domain of ERP & e-Commerce. A ray of relief & satisfaction to  our customers heart by our successful deployment in their organization, purely represents our success in Odoo platform. Hence, we take pride for being an Odoo partner with a vision of expanding our strategic alliances with our customers to offer them high value-added, trustworthy & cost effective solutions.

 

Since establishment, our business has span across 11 countries of the world. Our customers are companies of all sizes ranging from start-ups to large enterprises, who realize that they need a professional business solutions to generate revenue streams, establish proper communication channels or streamline business operations. Standing with strong determination of customer satisfaction, observing each minute detail of their business processes, providing proper guidance and moving forth to develop product accordingly adds our value and reliability among our customers. 

 

We are blessed with efficient, passionate & eclectic young developers who have come across almost all kinds of business profiles, working with full dedication, applying creativity & new features in existing modules and completing customer's projects successfully on predefined target. Our in-depth knowledge while giving business solutions in Odoo allows us to offer following services to our customers :

 

  • Consulting
  • Installation, Configuration & Customization
  • Training & Support
  • Maintenance
  • Upgradation
  • Documentation
  • Crafting community modules
  • Drafting videos on demand
  • Smart Apps development

We will be :) to welcome you @ www.emiprotechnologies.com to solve any kind of your business needs around Odoo. However we are just an inch away from you by email info@emiprotechnologies.com or a tweet to @EmiproTech

Emipro Technologies Pvt. Ltd.
On 6/10/16, 1:22 AM

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

--Pawan--
1267
| 4 3 5
Hyderabad, India
--Pawan--


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

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

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