Limit the pivot report between 2 dates with wizard

Jakub Parcheta


It takes too long to generate the report because there are to many data.

I created a wizard with start_date and finish_date and I would like to know how to limit the report between both dates.

Wizard .py:

class GetDatesWizard(models.TransientModel):

    _name = 'get.dates.wizard'

    start_date = fields.Date("Start date")

    stop_date = fields.Date("Stop date")

    def create_report(self):

        return {

            'name': 'generate report',

            'type': 'ir.actions.act_window',

            'res_model': '',

            'view_mode': 'pivot',


Wizard .xml:

    <record id="view_get_dates_wizard" model="ir.ui.view">

        <field name="name">view.get.dates.wizard</field>

        <field name="model">get.dates.wizard</field>

        <field name="arch" type="xml">



                    <field name="start_date"/>

                    <field name="stop_date"/>



                    <button name="create_report" type="object" string="Create" class="oe_highlight"/>

                    <button name="cancel" string="Cancel" special="cancel" class="oe_link"/>





Report .py:

class CostPlateReport(models.Model):

    _name = ""

    _order = 'date desc'

    partner = fields.Many2one('res.partner','Client')

    date = fields.Date('Date')

    plate = fields.Char('Plato')

    cost = fields.Float('Cost')

    def _query(self, with_clause='', fields={}, groupby='', from_clause=''):

        with_ = ("WITH %s" % with_clause) if with_clause else ""

        select_ = """

            min( as id,

   as date,

            m.partner as partner,

   as plate,

            pc.cost as cost


        for field in fields.values(): 

            select_ += field

        from_ = """

                irco_menu m

                    join irco_menu_plates p on (

                        join res_partner r on (

                        join product_template pt on (

                            join irco_plate_cost pc on (

                            join product_product pp on (


        """ % from_clause

        groupby_ = """







        """ % (groupby)

        return "%s (SELECT %s FROM %s WHERE m.state = 'done' GROUP BY %s)" % (with_, select_, from_, groupby_)


    def init(self):

        tools.drop_view_if_exists(, self._table)"""CREATE or REPLACE VIEW %s as (%s)""" % (self._table, self._query()))

Report .xml:

    <record id="view_cost_plate_report" model="ir.ui.view">

         <field name="name"></field>

         <field name="model"></field>

         <field name="arch" type="xml">

             <pivot string="Cost Analysis" disable_linking="True">

                 <field name="date" interval="month" type="row"/>

                <field name="cost" type="measure"/>