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 return different views in a method? Please someone help me.. Thanks in advance

By
Alcaline
on 1/22/15, 2:15 AM 725 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

   

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.

Aldennis
on 9/5/15, 7:09 AM

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, }

Aldennis
on 9/5/15, 7:12 AM

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.

Aldennis
on 9/5/15, 7:31 AM
0

Ben Bernard

--Ben Bernard--
1083
| 4 3 6
Jakarta, Indonesia
--Ben Bernard--
Ben Bernard
On 1/23/15, 4:18 AM

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

@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.

Ivan
on 1/23/15, 6:12 AM
0

Ivan

--Ivan--
3210
| 5 3 6
Jakarta, Indonesia
--Ivan--
Ivan
On 1/22/15, 4:46 AM

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.

i'll try this Ivan thanks.

Alcaline
on 1/22/15, 5:26 AM

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.

Alcaline
on 1/22/15, 5:31 AM

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

Ivan
on 1/22/15, 10:45 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: 1/22/15, 2:15 AM
Seen: 725 times
Last updated: 9/5/15, 7:31 AM