Skip to Content
Menu
This question has been flagged
2 Replies
5988 Views

I've created a wizard that views the account.move.line and i want the data of this to be filter by DATE, PERIOD, and FISCAL YEAR using the domain. but when i run it, it does not pop up the wizard and automatically close the whole wizard. Can someone please help me in this problem?

 

Here is my code:

.xml:

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

            <field name="name">Extended Tax Report</field>

            <field name="model">biz1.tax.report</field>

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

                <form string="Filter" version="7.0">

                    <sheet>

                        <label string="" />  <!-- binding for inherited views -->

                        <group col="4">

                            <field name="chart_account_id" widget='selection'

                                on_change="onchange_chart_id(chart_account_id, context)" />

                            <field name="company_id" invisible="1" />

                            <field name="fiscalyear_id" domain="[('company_id','=',company_id)]" />

                            <field name="target_move" />

                        </group>

                        <notebook tabpos="up" colspan="4">

                            <page string="Filters" name="filters">

                                <group>

                                    <field name="filter" on_change="onchange_filter(filter, fiscalyear_id)" />

                                </group>

                                <group string="Dates"

                                    attrs="{'invisible':[('filter', '!=', 'filter_date')], 'required':[('filter', '=', 'filter_date')]}">

                                    <field name="date_from" />

                                    <field name="date_to" />

                                </group>

                                <group string="Periods"

                                    attrs="{'invisible':[('filter','!=','filter_period')], 'required':[('filter', '=', 'filter_period')]}">

                                    <field name="period_from" domain="[('fiscalyear_id', '=', fiscalyear_id)]" />

                                    <field name="period_to" domain="[('fiscalyear_id', '=', fiscalyear_id)]" />

                                </group>

                            </page>

                            <page string="Journals" name="journal_ids">

                                <field name="journal_ids" />

                            </page>

                        </notebook>

                        <footer>

                            <button name="check_report" string="Print" type="object"

                                default_focus="1" class="oe_highlight" />

                            or

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

                        </footer>

                        <button icon="gtk-cancel" special="cancel" string="Cancel" />

                        <button icon="gtk-ok" name="action_button_ok" string="Filter Data"

                            type="object" />

                    </sheet>

                </form>

            </field>

        </record>

        

        

         <record id="action_tax_reports" model="ir.actions.act_window">

            <field name="name">Extended Tax Report</field>

            <field name="res_model">biz1.tax.report</field>

            <field name="view_type">form</field>

            <field name="view_mode">form</field>

            <field name="view_id" ref="biz1_tax_views"/>

            <field name="target">new</field>

        </record>

        <menuitem icon="STOCK_JUSTIFY_FILL" name="Tax Report" id="menu_tax_report"

            parent="account.menu_finance_entries" action="action_tax_reports"

            sequence="11" />

.py

def action_button_ok(self, cr, uid, ids, context=None):

      account_ids = []

      account_tax_ids = self.pool.get('account.tax').search(cr,uid,[('id','!=',0)],context= context)

      netsvc.Logger().notifyChannel("\n0000000000  ", netsvc.LOG_INFO, ''+str(account_tax_ids))

      for account_tax in self.pool.get('account.tax').browse(cr,uid,account_tax_ids,context=context):

          netsvc.Logger().notifyChannel("\n111111111  ", netsvc.LOG_INFO, ''+str(account_tax))

          account_ids.append(account_tax.account_collected_id.id)

          account_ids.append(account_tax.account_paid_id.id)

#           netsvc.Logger().notifyChannel("\n  ", netsvc.LOG_INFO, ''+str(finish))

      action1 = []  

      for wizard in self.browse(cr,uid,ids, context=context):

          netsvc.Logger().notifyChannel("\n222222  ", netsvc.LOG_INFO, ''+str(account_tax))

         

          if wizard.filter == 'date':

               netsvc.Logger().notifyChannel("\n333333333  ", netsvc.LOG_INFO, ''+str(wizard.search_selection))

               action1 = {

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

                    'res_model': 'account.move.line',

                    'view_mode': 'tree',

                    'view_type': 'tree',

                    'domain':[('date','>=',wizard.date_from), ('date', '<=', wizard.date_to)] ,

                    'views': [(False, 'tree')],

                    'target': 'new',

                     }

              

          elif wizard.filter == 'period':

          

              action1= {

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

                    'res_model': 'account.move.line',

                    'view_mode': 'tree',

                    'view_type': 'tree',

                    'domain':[('period_id','>=',wizard.period_from), ('period_id','<=',wizard.period_to)] ,

                    'views': [(False, 'tree')],

                    'target': 'new',

                     }

        

          return action1

   

Avatar
Discard

I've done this before but using a different approach. In your .py file, using search function, get all the record ids of the account_move_line records that you want to display. Filter it according to your needs (i.e. Date, Period and Fiscal Year) and put all of these ids in one list (move_line_ids). Then in your action1 domain put: [('id','in',(move_line_ids))], Make your 'target':'current'. Hope this helps.

This is my return method: return { 'name':_(title), 'view_mode': 'tree', 'view_id': view_id, 'view_type': 'form', 'res_model': 'account.move.line', 'type': 'ir.actions.act_window', 'nodestroy': True, 'target': 'current', 'domain': [('id','in',(move_line_ids))], 'context': {}, 'limit': limit, }

The 'limit' attribute is optional. In my case, I want to display all records in one page if it is greater than 80. You also need to have both 'view_mode' and 'view_type' included in your return.

Best Answer

You have to have an else in the if-elif structure just in case.

AFAIK you need to put form,tree in the view_mode (tree alone does not work).

'views': [(False, 'tree')] is not required if you don't have specific view to call.

In general, check that your return value is a proper action call.

Avatar
Discard
Author

i'll try this Ivan thanks.

Author

hi Ivan i've already try this one but nothing happen. the output is still the same. the wizard is automatically closing. when i click the button.

Can you post what is returned from that method? Log the return value before the return statement.

Best Answer

I think you forget to set the 'view_id' key for action dictionary.

Avatar
Discard

@Bernard view_id is not compulsory if you don't have any specific view in mind. It will just take the first view based on the model and type requested ordered by priority and then name.