【问题标题】:Openerp: onChange event to create lines on account moveOpenerp:onChange 事件以在帐户移动时创建行
【发布时间】:2012-09-14 15:40:47
【问题描述】:

我在日记帐分录(帐户移动表单)上有一个字段 amount,我需要定义一个 onChange 事件,该事件在我填写金额后自动插入行。但我不确定如何。

【问题讨论】:

    标签: python onchange openerp


    【解决方案1】:

    昨天我不得不做一些与您的要求类似的事情。我在购买中有一个销售订单(m2o)字段...on_change of sale_order 我必须填写采购订单行...希望它可以帮助您。

    class purchase_order(osv.osv):
        _inherit = 'purchase.order'
    
        _columns = {
            'sale_order':fields.many2one('sale.order','Sale Order'),
            'purchase_type':
                fields.selection([
                    ('order','Purchase Order'),
                    ('job','Job Order')
                    ],
                'Purchase Type',
                required=True,
                states={
                    'confirmed':[('readonly',True)],
                    'approved':[('readonly',True)],
                    },
                select=True,
                help="Define type of purchase order.",
             ),
         }
    
    def onchange_saleorder(self,cr,uid,ids,order,context=None):
        res={}
        lis=[]
        sorder_id=self.pool.get('sale.order').browse(cr,uid,order)
        for line in sorder_id.order_line:
            print "uom",line.product_id.uom_id.id
            res={'product_id':line.product_id.id,
                 'name':line.product_id.name,
                 'product_qty':1,
                 'product_uom':line.product_id.uom_id.id,
                 'price_unit':line.price_unit,
                 'date_planned':time.strftime('%Y-%m-%d'),}
            lis.append(res)
        print "list is .........",lis
        res={'value':{'order_line':lis}} // here order_line is o2m field of purchase.
        return res
    

    【讨论】:

      【解决方案2】:

      您的 on_change 方法必须返回由行值组成的字典列表。

      例如:

      res['value']['line_ids'] = [
          {
              'account_id': 1,
              'debit': 100,
          },
          {
              'account_id': 2,
              'credit': 100,
          }]
      

      另外,以 account.voucherrecompute_voucher_lines 方法为例。

      【讨论】:

        【解决方案3】:

        有时会生成错误“0”,因此我们必须编写这样的代码。 在上述示例的情况下 lis.append((0,0,res))

        【讨论】:

          猜你喜欢
          • 2012-02-16
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2020-11-06
          • 1970-01-01
          • 2021-02-08
          • 2019-04-25
          • 2014-05-30
          相关资源
          最近更新 更多