函数on_change openerp8不起作用

时间:2016-12-27 15:03:53

标签: openerp

我想添加一个列,我计算两列的总和,但这里不起作用是我的代码

test.py:

from openerp.osv import fields, osv
class sale_order_line(osv.osv):
_inherit = 'account.bank.statement.line'
_name = 'account.bank.statement.line'
_columns = {
'colx': fields.float(),
'coly': fields.float(),
}
def onchange_result(self, cr, uid, ids, colx, amount, context=None):
    res = {}
    if amount and colx:
        res['coly'] = amount + colx
    return {'value': res}

的test.xml

<?xml version="1.0" encoding="utf-8"?>
<openerp>
   <data>
      <record model="ir.ui.view" id="account_statement_instructor1_form_viewfzz">
        <field name="name">account.statement.form.viewfzz</field>
        <field name="model">account.bank.statement</field>
        <field name="inherit_id" ref="account.view_bank_statement_formfz"/>
        <field name="arch" type="xml">
            <xpath expr="//sheet/notebook/page/field[@name='line_ids']/tree/field[@name='date']" position="after">
            <field name="colx" on_change="onchange_result(amount, colx)"/>
            <field name="amount" on_change="onchange_result(amount, colx)"/>
            <field name="coly"/>
           </xpath>
        </field>
      </record></data></openerp>

谢谢

1 个答案:

答案 0 :(得分:0)

test.py

from openerp.osv import fields, osv
class sale_order_line(osv.osv):
_inherit = 'account.bank.statement.line'
_name = 'account.bank.statement.line'
_columns = {
'colx': fields.float(),
'coly': fields.float(),
}
#This method will be called when either the field CostPrice or the field ShippingCost changes.
def on_change_price(self,cr,user,ids,colx,amount,context=None):
#Calculate the total
total = colx + amount
    res = {
        'value': {
    #This sets the total price on the field standard_price.
            'coly': total
      }
}
#Return the values to update it in the view.
return res

的test.xml:

<?xml version="1.0" encoding="utf-8"?>
  <openerp>
    <data>
      <record model="ir.ui.view" id="account_statement_instructor1_form_viewfzz">
        <field name="name">account.statement.form.viewfzz</field>
        <field name="model">account.bank.statement</field>
        <field name="inherit_id" ref="account.view_bank_statement_formfz"/>
        <field name="arch" type="xml">
          <xpath expr="//sheet/notebook/page/field[@name='line_ids']/tree/field[@name='partner_id']" position="after">
            <field name="colx" on_change="on_change_price(amount,colx)" string="Montant Crédit"/>
            <field name="coly" string="Rest"/>
        </xpath>
        </field>
    </record></data></openerp>