2017-08-07 128 views
0

我有客戶表單中的customer和deposit字段,其實是one2many,但用戶在存款中添加一行並提交或編輯一些現有的。我想對這個事件做一些計算。我嘗試了onchangecompute,但兩者都不起作用。Odoo - 添加或編輯one2many字段的計算

+0

你能用你試過的東西在XML字段和Python字段中添加一段摘錄嗎? – travisw

回答

0

添加或編輯One2many字段是FormView。

所以你只要把現場什麼你做什麼FormView控件中的* .xml

防爆計算。我SUM字段

<!-- FormView --> 
     <record model="ir.ui.view" id="view_nstda_bst_dbill_form"> 
      <field name="name">nstda.bst.dbill.form</field> 
      <field name="model">nstda.bst.dbill</field> 
      <field name="type">form</field> 
      <field name="arch" type="xml"> 
       <form string="nstda_bst_dbill" class="nstda_bst_dbill_form" > 
        <group> 
         <field name="status" invisible="1" /> 
         <field name="matno" /> 
<!--      <field name="matdesc" /> --> 

         <label for="balance" /> 
         <div> 
          <field name="balance" style="width: 20%%" /> 
          <field name="uom_1" style="width: 10%%;" 
           attrs="{'invisible':[('matno','=',False)]}" /> 
         </div> 

         <label for="balance_rs" /> 
         <div> 
          <field name="balance_rs" style="color:Red;width: 20%%" /> 
          <field name="uom_2" style="width: 10%%;" 
           attrs="{'invisible':[('matno','=',False)]}" /> 
         </div> 

         <label for="qty" /> 
         <div> 
          <field name="qty" style="width: 20%%" 
           attrs="{'required':[('status','in',['draft','edit',False])]}" /> 
          <field name="uom" style="width: 10%%;" 
           attrs="{'invisible':[('matno','=',False)]}" /> 
         </div> 

<!--      <field name="unitprice" /> --> 
         <label for="unitprice" /> 
         <div> 
          <field name="unitprice" style="width: 20%%" /> 
          <field name="currency" style="width: 10%%;" /> 
         </div> 

         <field name="sum" invisible="1" /> 
         <field name="dbill_discount_sum" invisible="1" /> 
        </group> 
       </form> 
      </field> 
     </record> 

和*的.py一邊是...

例。

@api.one 
@api.onchange('qty','matno') 
@api.depends('qty','matno') 
def _set_sum(self): 
    self.sum = self.unitprice * self.qty 


sum = fields.Float(string="summary", store=True, compute='_set_sum') 
matno = fields.Many2one('bst.stock', 'matno') 
qty = fields.Integer('qty')