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.
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
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.
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
Thank You Axel! it worked.
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">
<td class="text-center oe_leftfit oe_rightfit" style="background-color: <t t-esc="day['color']"/>!important; font-size: 12px; min-width: 24px"> <t t-esc="day['day_str']"/></td>
<t t-set="total_days" t-value="total_days+1" />
</t>
….
Output of Qweb report:
I hope it help you.
Create an account today to enjoy exclusive features and engage with our awesome community!
Sign upRelated Posts | Replies | Views | Activity | |
---|---|---|---|---|
|
1
Aug 20
|
1820 | ||
|
5
Dec 19
|
9817 | ||
|
4
Jan 19
|
3186 | ||
|
1
Jan 19
|
6390 | ||
|
2
Jan 19
|
8755 |