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 can i toggle a button based on field value?

By
samba
on 9/15/14, 4:51 AM 802 views

I am writing a scritpt to reconcile bank statements. I am showing all  account_move_lines that depend on bank accounts. For every line i want to show one of the two buttons "reconcile" or "unreconcile" based on the field value "bankreconcilestate". It has two states "draft" and "reconciled". If bankreconcilestate="draft" then "reconcile" else "unreconcile" button should show. I have written the below code for this scenario.

__init__.py

*****************************************************************************************************

import bank_transaction

****************************************************************************************************

bank_transaction.py

*****************************************************************************************************

from openerp.osv import osv,fields
from openerp import tools
class bank_transaction(osv.osv):
    _inherit = "account.move.line"
    def unreconcile(self,cr,uid,ids,context=None):
        self.write(cr,uid,ids,{'state':'confirmed','bankreconcile_ref':None },context)
    
    def reconcile_bank_transaction(self,cr,uid,ids,context=None):
        bankreconcile_ref_sequence= self.pool.get('ir.sequence').next_by_code(cr, uid, 'bankreconcile_ref_sequence_code')
        self.write(cr,uid,ids,{'bankreconcile_ref':bankreconcile_ref_sequence,'bankreconcilestate':'reconciled'},context)
    _columns={
    'bankreconcile_ref':fields.char("Bankreconciliation Ref"),
    'bankreconcilestate': fields.selection([('draft','Draft'),('reconciled','Reconciled')], 'Bank Recon Status', readonly=True),
    }
    _defaults={
    'bankreconcilestate':'draft'
    }
bank_transaction()

****************************************************************************************************

bank_transaction_view.py

*****************************************************************************************************

<openerp>
  <data>
      <record model="ir.ui.view" id="bank_transactions_view_tree">
        <field name="name">view.bank.transactions.tree</field>
    <field name="model">account.move.line</field>
        <field name="arch" type="xml">
            <tree string="All Bank Transactions">
            <field name="id"/>
            <field name="name"/>
            <field name="journal_id"/>
            <button name="reconcile_bank_transaction"
                            string="Reconcile"
                            type="object"/>
            <field name="bankreconcile_ref"/>
            <field name="account_id"/>
            </tree>  
        </field>  
      </record>
<record id="view_ bank_trans_search" model="ir.ui.view">
            <field name="name">view.bank.trans.search</field>
            <field name="model">account.move.line</field>
            <field name="arch" type="xml">
                <search>
                    <filter name="onlybanktransactions" domain="[('journal_id.type','=','bank'),('account_id.type','=','liquidity')]" string="Only bnak journals"/>
                    <group string="Group by...">
                                            <filter name="grp_journal_id" string="Journals" domain="[]" context="{'group_by':'journal_id'}"/>
                    </group>
                </search>
            </field>
    </record>
     <record model="ir.actions.act_window" id="action_bank_transaction_tree">
            <field name="name">Reconcile Bank Transactions</field>
            <field name="type">ir.actions.act_window</field>
            <field name="res_model">account.move.line</field>
            <field name="view_type">form</field>
             <field name="context">{"search_default_onlybanktransactions":1,"search_default_grp_journal_id":1}</field>
            <field name="view_mode">tree,form</field>
            <field name="search_view_id" ref="view_ bank_trans_search"/>
            <field name="view_id" ref="bank_transactions_view_tree"/>
        </record>
        <record forcecreate="1" id="bankreconcile_ref_sequence_id_extension" model="ir.sequence.type">
             <field name="name">bankreconcile_ref_sequence_name</field>
             <field name="code">bankreconcile_ref_sequence_code</field>
        </record>
        <record forcecreate="1" id="seq_id" model="ir.sequence">
            <field name="name">bankreconcile_ref_sequence_name</field>
            <field name="code">bankreconcile_ref_sequence_code</field>
        </record>
        <menuitem string="Bank Transactions view"
          action="action_bank_transaction_tree"
          id="menu_bank_transaction_tree"
          parent="account.menu_finance_bank_and_cash" sequence="9"/>
  </data>
</openerp>

 

****************************************************************************************************

When i write attrs for button attrs="{'invisible':[('bankreconcilestate','=','reconciled')]}" in tree view it is showing the error "

Error: QWeb2 - template['ListView.rows']: Runtime Error: Error: QWeb2 - template['ListView.row']: Runtime Error: Error: Unknown field bankreconcilestate in domain [["bankreconcilestate","=","reconciled"]]

http://localhost:8069/web/webclient/js?db=kell1:2446

". I have checked in table "account_move_line" this field is there, but giving error like this. How can i solve this problem?

1

deep

--deep--
1617
| 5 4 7
Bengaluru, India
--deep--

Techno-Functional Associate with 6+ years of experience in Odoo (formerly known as OpenERP).

deep
On 9/15/14, 5:34 AM

Firstly Add "bankreconcilestate" field in the view, then you can set the attributes...

Here it goes:

  <tree string="All Bank Transactions">

             ...
            <field name="bankreconcilestate" invisible="1"/>
            <button name="reconcile_bank_transaction"
                            string="Reconcile"
                            type="object"

                            attrs="{'invisible':[('bankreconcilestate','=','reconciled')]}"/>
        </tree>  

 

 

in XML, any field which are used to set any attributes/property, then dependency field must be present in that view... hope this helps you

deep
on 9/15/14, 5:36 AM

Thanks Deep,

samba
on 9/15/14, 5:44 AM

HI deep Please check this question. Raising error while i am printing invoices . https://www.odoo.com/forum/help-1/question/invoice-print-giving-this-error-not-enough-space-handle-pagebegin-args-type-exceptions-valueerror-valueerror-not-enough-space-n-handle-pagebegin-args-traceback-object-at-0x7fdb1c796950-can-any-one-please-help-me-62861

samba
on 9/16/14, 8:05 AM

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: 9/15/14, 4:51 AM
Seen: 802 times
Last updated: 3/16/15, 8:10 AM