Pablo Escobar
Pablo Escobar

Reputation: 685

How to solve this InvalidDatetimeFormat error in Odoo 11

I'm getting the error:

InvalidDatetimeFormat: invalid input syntax for type date: "%Y-%m-%d" LINE 1: ...,12))) AND ("sale_order_line"."confirm_date" >= '%Y-%m-%d'...

My code from wizard is:

@api.multi
    def export_xls(self):
        context = self._context
        datas = {'ids': context.get('active_ids', [])}
        datas['model'] = 'wizard.stock.history'
        tmp = self.read(['start_date', 'end_date'])
        if len(tmp) > 0:
            datas['form'] = tmp[0]
        for field in datas['form'].keys():
            if isinstance(datas['form'][field], tuple):
                datas['form'][field] = datas['form'][field]
        if context.get('xls_export'):
            return self.env.ref('product_category_report.stock_xlsx').report_action(self, data=datas)

And my code from rendering is:

sale_obj = self.env['sale.order.line'].search([('order_id.state', 'in', ('sale', 'done')),
                                                       ('product_id', '=', product.id),
                                                       ('order_id.warehouse_id', '=', warehouse),
                                                       ('confirm_date', '>=', start_date),
                                                       ('confirm_date', '<=', end_date)])

I was taking stock reports from the odoo v11. But in this scenario, the error is happening like this. I don't know why, I have tried in many other ways, still the error is there.

Upvotes: 0

Views: 733

Answers (1)

Anitha Das B
Anitha Das B

Reputation: 372

Please convert the start date and end date to datetime if confirm date is datetime field, using below code

start_date = datetime.strptime(start_date,"%Y-%m-%d").strftime("%Y-%m-%d %H:%M:%S")
end_date = datetime.strptime(end_date,"%Y-%m-%d").strftime("%Y-%m-%d %H:%M:%S")

Upvotes: 2

Related Questions