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 call a function defined in python in a mako file?

By
Drees Far
on 8/24/15, 5:22 AM 719 views

Hello everybody!

Please guys who can help me know how after defining a function in my python file can i call  it in a mako file to create iteration in a report.

Need an answer friends.

Please who can clarify this point please.

Regards and thanks a lot ;)


0
kaisusr
On 8/24/15, 5:28 AM


Example:

the python function:

def compta_fct_budget_struct_sum(self, cr, uid, ids, budget_id, struct, ca_ids,periodedu,periodeau, context=None):

return sum

Mako call:

<% budget_somme = analyique.compta_fct_budget_struct_sum(budget_id,strct.id,[[ca.id]],periodedu,periodeau) %>

Thanks a lot for you answer friend. But, please o, the mako file i make ${line.?????} in a td ??

Drees Far
on 8/24/15, 5:32 AM

for example if you want to show the value of budget_somme in a TD: ${budget_somme} Please don't forget to mark my answer as a valide answer

kaisusr
on 8/24/15, 5:35 AM

what is analytique ??? in mako!!

Drees Far
on 8/24/15, 5:36 AM

Dont worry if that works for me i will make it valide i promise ;)

Drees Far
on 8/24/15, 5:37 AM

analytique is like line in your report

kaisusr
on 8/24/15, 5:40 AM

I have tried it but i got that error please help please

Drees Far
on 8/24/15, 5:43 AM
0

Drees Far

--Drees Far--
1130
| 5 2 6
Tunis, Tunisia
--Drees Far--
Drees Far
On 8/24/15, 5:34 AM

Here is my python function:


def get_lines(self, payslip,cr,uid, context=None):

ret = []

obj = self.pool.get('hr.employee')

obj_ids = obj.search(cr, uid, [])

res = obj.read(cr, uid, obj_ids, ['id'], context)

for r in res :

if r['name_related'] != 'Administrator' :

line_data = dict()

line_data['name']= r['name_related']

print r['name_related']

ret.append(line_data)

return ret

And in my mako:

%for obj in objects:

<% lines = obj.get_lines(payslip) %>
%for line in lines:
 <tr style='height:20.65pt'>
  <td width=31.9 style='width:31.9pt;border:none;border-bottom:solid windowtext 1.0pt;
  background:#FCE4D6;padding:0cm 3.5pt 0cm 3.5pt;height:14.65pt'>
  <p class=MsoNormal align=center style='margin-bottom:0cm;margin-bottom:.0001pt;
  text-align:center;line-height:normal'><b><span style='font-size:8.0pt;
  font-family:"Arial","sans-serif";color:black'>Nom Employé</span></b></p>
  </td>


  <td width=31.9 style='width:31.9pt;border:none;border-bottom:solid windowtext 1.0pt;
  background:#FCE4D6;padding:0cm 3.5pt 0cm 3.5pt;height:14.65pt'>
  <p class=MsoNormal align=center style='margin-bottom:0cm;margin-bottom:.0001pt;
  text-align:center;line-height:normal'><b><span style='font-size:8.0pt;
  font-family:"Arial","sans-serif";color:black'> ${line}</span></b></p>
  </td>

 </tr>

%endfor

%endfor

And i get this:

AttributeError: 'Undefined' object has no attribute 'get_lines'

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: 8/24/15, 5:22 AM
Seen: 719 times
Last updated: 8/24/15, 5:42 AM