This question has been flagged
1 Reply
9141 Views

Everything works fine at me local but when i've tried to put it in a testaddons(to test if my codes really works). I add a fields in JOURNAL ENTRIES but one field that has a name of 'mem' always appeared everytime i click the menu and the error keeps saying "Uncaught Error: NameError: name 'mem' is not defined".

 

Here's my code:

xml:

<!--*********************** Account.Entry Edition ****************** -->
        <record id="view_move_form" model="ir.ui.view">
            <field name="name">account.move.form</field>
            <field name="model">account.move</field>
            <field name="inherit_id" ref="account.view_move_form" />
            <field name="priority">1</field>
            <field name="arch" type="xml">
                <data>
                    
                    <xpath expr="//form/sheet/notebook/page/field[@name='line_id']" position="replace">
                         <field name="line_id" widget="one2many_list"
                              context="{'line_id': line_id , 'journal_id': journal_id, 'default_mem': mem, 'default_pr_num':pr_num, 'default_or_num':or_num, 'default_cv_num':cv_num, 'default_cheque_num':cheque_num,  }">

                                <form string="Journal Item" version="7.0">
                                    <group col="6" colspan="4">
                                        <field name="name"/>
                                        <field name="ref"/>
                                        <field name="partner_id" on_change="onchange_partner_id(False, partner_id, account_id, debit, credit, date, journal_id, context)"/>
                                        
                                        <field name="journal_id"/>
                                        <field name="period_id"/>
                                        <field name="company_id" required="1" groups="base.group_multi_company"/>
                                    </group>
                                    <notebook colspan="4">
                                        <page string="Information">
                                            <group>
                                                <group string="Amount">
                                                    <field name="account_id" domain="[('company_id', '=', parent.company_id), ('type','&lt;&gt;','view'),('type','&lt;&gt;','consolidation')]"/>
                                                    <field name="debit"/>
                                                    <field name="credit"/>
                                                    <field name="quantity"/>
                                                </group>

                                                <group string="Accounting Documents">
                                                    <field name="invoice"/>
                                                    <field name="move_id" required="False"/>
                                                    <field name="statement_id"/>
                                                </group>

                                                <group string="Dates">
                                                    <field name="date"/>
                                                    <field name="date_maturity"/>
                                                    <field name="date_created"/>
                                                </group>

                                                <group string="Taxes">
                                                    <field name="tax_code_id"/>
                                                    <field name="tax_amount"/>
                                                    <field name="account_tax_id" domain="[('parent_id','=',False)]"/>
                                                </group>

                                                <group string="Currency" groups="base.group_multi_currency">
                                                    <field name="currency_id"/>
                                                    <field name="amount_currency"/>
                                                </group>

                                                <group string="Reconciliation">
                                                    <field name="reconcile_id"/>
                                                    <field name="reconcile_partial_id"/>
                                                </group>

                                                <group string="States">
                                                    <field name="state"/>
                                                    <field name="blocked"/>
                                                </group>

                                                <group groups="analytic.group_analytic_accounting" string="Analytic">
                                                    <field name="analytic_account_id"/>
                                                </group>
                                            </group>
                                            <separator string="Internal Note"/>
                                            <field name="narration"/>
                                        </page>
                                        <page string="Analytic Lines" groups="analytic.group_analytic_accounting">
                                            <field colspan="4" name="analytic_lines" nolabel="1" context="{'default_general_account_id':account_id, 'default_name': name, 'default_date':date, 'amount': (debit or 0.0)-(credit or 0.0)}"/>
                                        </page>
                                    </notebook>
                                </form>
                                <tree colors="blue:state == 'draft';black:state == 'posted'" editable="top" string="Journal Items">
                                    <field name="invoice"/>
                                    <field name="name"/>
                                    <field name="partner_id" on_change="onchange_partner_id(False, partner_id, account_id, debit, credit, parent.date, parent.journal_id, context)"/>
                                    <field name="account_id" domain="[('journal_id','=',parent.journal_id),('company_id', '=', parent.company_id)]"/>
                                    <field name="date_maturity"/>
                                    <field name="debit" sum="Total Debit"/>
                                    <field name="credit" sum="Total Credit"/>
                                    <field name="analytic_account_id" groups="analytic.group_analytic_accounting"/>
                                    <field name="amount_currency"/>
                                    <field name="currency_id" groups="base.group_multi_currency"/>
                                    <field name="tax_code_id"/>
                                    <field name="tax_amount"/>
                                    <field name="state"/>
                                    <field name="reconcile_id"/>
                                    <field name="pr_num" invisible="True"/>
                                    <field name="or_num" invisible="True"/>
                                    <field name="cv_num" invisible="True"/>
                                    <field name="cheque_num" invisible="True"/>
                                    <field name="mem" invisible="True"/>

                                    <field name="reconcile_partial_id"/>
                                </tree>
                            </field>
                
                        
                    </xpath>
                </data>
            </field>
        </record>

python:

class account_move(osv.osv):
    _inherit = 'account.move'  

  _columns ={
               'or_num': fields.char('O.R. Number', size=50),
               'cheque_num': fields.char('Cheque Number', size=50),
               'pr_num': fields.char('P.R. Number', size=50),
               'cv_num': fields.char('C.V. Number', size=50),
               'mem':fields.char('Memo', size=50),
               }

account_move()

Avatar
Discard
Best Answer

Your view is defined for account.move and then it displayed line_id (which is account.move.line, I believe).  The fields mem, pr_num, etc. fields are specified to be displayed for account.move.line (it is displayed from within the tree tag).  Now, what you have specified within the python is that those fields are defined for account.move but not displayed (I'm not sure if it is also defined for account.move.line but I presume they must be because there is no installation/upgrade error).

In order for the context to work, the fields used (mem, pr_num, etc.) need to be displayed for account.move's form view.  So, if you change add those fields into the view (not within the line_id fields but outside, or more specifically outside the xpath), it should work.

Avatar
Discard
Author

Thanks Ivan for your help:) i already solved the problem

Author

Thanks Ivan for your help:) i already solved the problem