Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

How to filter by date in a wizard in odoo 8

By
Abayomi Olatidoye
on 11/25/16, 5:45 PM 142 views

Hi,

Can any one help with code to create a wizard with date filter

I have already created the report to be generated which works well but my wizard brings all the data in the database not the specific date selected.

I am using odoo 8.

Will appreciate a quick response.

Thanks.


0

Jignesh Mehta

--Jignesh Mehta--
2087
| 6 4 8
Surat, India
--Jignesh Mehta--


Jignesh Mehta
On 11/26/16, 6:02 AM

Hello Abayomi Olatidoye,


Add two date fields in the wizard like start_date and end_date.

Create a method for wizard button and you can check the records which is between start_date and end_date.

Ex:-


@api.multi

def method(self):

     self.ensure_one()

     data = {}

     data['ids'] = self.env.context.get('active_ids', [])

     data['model'] = self.env.context.get('active_model', 'ir.ui.menu')

     data['form'] = self.read(['start_date', 'end_date'])[0]

     record_search_obj = self.env['model.name'].search([('model_date_field', '>=', self.start_date), ('model_date_field', '<=', self.end_date)]).ids

     datas = {

         'ids': record_search_obj,

         'model': 'model.name',

         'form': record_search_obj,

         }

     return {

         'type': 'ir.actions.report.xml',

         'report_name': 'module_name.report_id',

         'datas': datas}


Hope this code will helps you.

Thanks,

Many thanks for your response. I adapted your code to my usage in the way below, but got this error "TypeError: print_payroll_schedule_report() takes exactly 1 argument (5 given)"

import time

from datetime import datetime

from dateutil import relativedelta

from openerp.osv import fields, osv

class ReportWizard(osv.osv_memory):

_name = 'bluspiral.sche.schedule'

# _inherit = 'account.invoice'

_description = 'Cash Payroll Schedule'

_columns = {

'date_from': fields.date('Date From', required=True),

'date_to': fields.date('Date To', required=True),

}

_defaults = {

'date_from': lambda *a: time.strftime('%Y-%m-01'),

'date_to': lambda *a: str(datetime.now() + relativedelta.relativedelta(months=+1, day=1, days=-1))[:10],

}

def print_payroll_schedule_report(self):

self.ensure_one()

data = {}

data['ids'] = self.env.context.get('active_ids', [])

data['model'] = self.env.context.get('active_model', 'ir.ui.menu')

data['form'] = self.read(['date_from', 'date_to'])[0]

record_search_obj = self.env['hr.payslip'].search(

{('date_from', '>=', self.date_from), ('date_to', '<=', self.date_to)}).ids

datas = {

'ids': record_search_obj,

'model': 'bluspiral.sche.schedule.template',

'form': tree_search_obj,

}

return {

'type': 'ir.actions.report.xml',

'report_name': 'bluspiral_sche.cash_report',

'datas': datas}

Abayomi Olatidoye
on 11/27/16, 8:03 AM

In form of datas, you need to pass the search records which is record_search_ids. and my code is in odoo9.

Jignesh Mehta
on 11/27/16, 10:40 PM

it is also work in odoo 8.

Jignesh Mehta
on 11/27/16, 10:42 PM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 11/25/16, 5:45 PM
Seen: 142 times
Last updated: 11/26/16, 6:02 AM