Skip to Content
Menu
This question has been flagged
1 Reply
5209 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.


Avatar
Discard
Best Answer

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,

Avatar
Discard
Author

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}

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

it is also work in odoo 8.