This question has been flagged
9 Replies
4328 Views

Hello, i'm in odoo 10 in qweb report

I want to browse my invoices records ( <tr t-foreach="docs" t-as="o">)

and i want to sum the total_amount for all invoices where the date_invoice is in january, then for february etc...

I've tried this:

<t t-set="adquat_janvier" t-value="sum([o.amount_total for o in docs if date_invoice in ('20190101','20190131') ])"/>

But there is the following error 

SyntaxError: unexpected EOF while parsing

Error when compiling AST
SyntaxError: unexpected EOF while parsing (<unknown>, line 0)
Template: 1126
Path: /templates/t/t/t/t[2]
Node: <t t-content="True"/>

I've tried this too :
<t t-set="adquat_janvier" t-value="sum([(date_invoice in ('20190101','20190131') and o.amount_total)  for o in docs ])"/>

How can i set debug mode ? (with pdb ?) 

Avatar
Discard
Author Best Answer

Ok so I completely change my method : 

I've done a class and a method to teturn all the data I need :


class ReportCalendrierAdherent(models.AbstractModel):
_name = 'report.adquat_distribinox_report.report_calendrier_adherent'

@api.model
def get_report_values(self, docids, data=None):
    ...
    docargs = {
    'doc_ids': docids,
    'doc_model': 'account.invoice',
    'docs': self.env['account.invoice'].browse(docids),
    'arg_partner': invoices[0].partner_id,
    'arg_lines': lines,
    'arg_line_total': line_total,
    }
    return docargs
Avatar
Discard
Best Answer

Try this:

<t t-set="adquat_janvier"
t-value="sum([docs.filtered(lambda rec: rec.date_invoice >= datetime.date(2019,1,1) and rec.date_invoice <= datetime.date(2019,1,31)).mapped('amount_total')])"/>
Avatar
Discard
Author

Sorry it doesn't whork, this is the error :

Error to render compiling AST

TypeError: unsupported operand type(s) for +: 'int' and 'list'

Template: 1154

Path: /templates/t/t/t/table/tbody/tr/t

Node: <t t-set="adquat_janvier" t-value="sum([docs.filtered(lambda rec: rec.date_invoice in ('20190101','20190131')).mapped('amount_total')])"/>

what are docs here?

you should update rec.date_invoice in ('20190101','20190131') with proper date comparison

Author

docs are account.invoices

how can i do proper date comparison please?

Author

Do you know if i can do all my treatment in python and return the correct values at qweb at the end ?

for example:

str(datetime.date(2019,1,1)) in ('2019-01-01') or datetime.date(2019,1,1) == date(2019,1,1) or datetime.date(2019,1,1) in [datetime.date(2019,1,1),datetime.date(2019,1,2)]

check my updated answer, maybe you need this.