Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
3 Risposte
11292 Visualizzazioni

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
Abbandona
Risposta migliore

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
Abbandona
Autore

Thank You Axel! it worked.

Risposta migliore

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
Abbandona
Post correlati Risposte Visualizzazioni Attività
1
ago 20
2643
5
dic 19
11268
4
gen 19
4246
1
gen 19
7488
2
gen 19
10083