Skip to Content
Menu
This question has been flagged
3 Replies
10495 Views

Hi! I

i need to know that how to call a function in q web reports? please help me if you know or have any idea.

Avatar
Discard
Best Answer

You could use this existing answer

https://www.odoo.com/forum/help-1/question/how-to-define-a-custom-methods-functions-to-be-used-in-a-qweb-report-how-to-define-and-use-a-report-parser-92244

Avatar
Discard
Author

Thank You Axel! it worked.

Best Answer

Hi Dishan Madushanka,

For eg: I used “HrLeave” model and in this class, I prepared get_day() method for prints its values in Qweb report.

Python code:

class HrLeave(models.Model):

     

            #List of field
            ….
            #List of method
            ….
            #This method returns return list values and this values print in Qweb report.
@api.multi
 def get_day(self):
res = []
            start_date = fields.Date.from_string(self.date_from)
            c_date = datetime.strptime(self.date_from,"%Y-%m-%d")
            last_day_of_month = int(calendar.monthrange(c_date.year, c_date.month)[1])
            for x in range(0, last_day_of_month):
            color = '#ababab' if start_date.strftime('%a') == 'Sat' or start_date.strftime('%a') == 'Fri' else ''
            res.append({'day_str': start_date.strftime('%a'), 'day': start_date.day , 'color': color})
            start_date = start_date + relativedelta(days=1)
        return res

 

XML Code(Qweb Report):

In Qweb report ‘s xml file, i used get_day() method and prints its value.

…..

<t t-foreach="doc.get_day()" t-as="day">
        &lt;td class="text-center oe_leftfit oe_rightfit" style="background-color: <t t-esc="day['color']"/>!important; font-size: 12px; min-width: 24px"&gt; <t t-esc="day['day_str']"/>&lt;/td&gt;
          <t t-set="total_days" t-value="total_days+1" />
</t>

….

 

Output of Qweb report:

I hope it help you.

Avatar
Discard
Related Posts Replies Views Activity
1
Aug 20
1820
5
Dec 19
9817
4
Jan 19
3186
1
Jan 19
6390
2
Jan 19
8755