在one2many中添加整数字段的值并将它们存储在Openerp中

时间:2014-03-18 06:45:00

标签: openerp openerp-7

我有一个自定义模块,我正在收集付款的详细信息。我已经根据需要创建了字段和UI。现在在one2many字段中有一个字段“amount”,我需要所有“金额”的总和当我保存表单时,将它们存储在其他字段“total”中。         在 collectiondeatils.py 中,“payment_collection_details”是one2many字段.Amount是与“class payment.collection.details”相关的字段。现在点击保存我应该将金额总和给予“完整”字段,该字段存在于 collectiondetails.py 中。点击img1中的保存按钮我收到了img2中的错误

Error : " Uncaught Error: [_.sprintf] expecting number but found object"
 ![Img1][1]
 ![img2][2]

  [1]: http://i.stack.imgur.com/673h1.png
  [2]: http://i.stack.imgur.com/oiVYJ.png

我的代码:

Collectiondetails.py

from osv import osv
from osv import fields
from openerp.tools.translate import _
from openerp.tools import html2plaintext

class collection_details(osv.osv):
 _name = "collection.details"
 _description = "Collection Details"
 """docstring for collection_details"""
 def _total_amount(self, cr, uid, ids, field_name, arg, context=None):
    val1 = 0
    res = {}
    for order in self.browse(cr, uid, ids, context=context):
        res[order.id] = {
            'total' : 0,
        }
        for line in order.payment_collection_details:
            val1 += line.collection_amount
        res[order.id]['total'] = val1
    return res

 _columns={
    'client_name': fields.many2one('res.partner','Client Name'),
    'client_id': fields.char('Client Id',size=64),
    'mobile': fields.char('Mobile',size=15),
    'order_value':fields.integer('Order value',size=5),
    'payment_terms':fields.many2one('collection.details.paymentterms','Payment Terms'),
    'mode_of_payment':fields.selection([('cash','Cash'),('creditcard','Credit Card'),('cheque','Cheque'),('ecs','ECS'),('bajaj','Bajaj')],'Mode of Payment'),
    'payment_collection_details': fields.one2many('collection.details.payments','order_id','Collection Details'),
    'dateof_documentsRecieved': fields.date('Date od Documents recieved at HO'),
    'ecs_status':fields.selection([('recieved','Recieved'),('senttobank','Sent to Bank'),('approved','Approved by Bank'),('rejected','Rejected by Bank')],'Status of ECS Mandate'),
    'total': fields.function(_total_amount,string='Total',help="Total amount that can be collected using collection table is")
 }


 def onchange_client_name(self, cr, uid, ids, part, context=None):
    part = self.pool.get('res.partner').browse(cr, uid, part, context=context)
    val = {
        'client_id':part.client_id,
        'mobile':part.mobile,
        'order_value':part.order_value
    }
    return {'value': val}

class collection_details_paymentterms(osv.osv):
    _name = "collection.details.paymentterms"
    _description = "Payment Terms"
    _order = "name"
    _columns = {
        'name' : fields.char('Payment Term',size=64),
        'schemedescription': fields.char('Scheme Description',size=64)
    }
class collection_details_payments(osv.osv):
    _name="collection.details.payments"
    _description = "Collection Payments"
    _order = "name"
    _columns={
        'order_id': fields.many2one('collection.details', 'Order Reference',  ondelete='cascade', select=True,required=True),
        'name' : fields.char('Sl.No',size=64),
        'date' : fields.date('Date'),
        'collection_amount': fields.integer('Amount',size=5),
        'bank_name':fields.char('Bank Name',size=64),
        'cheque_no': fields.char('Cheque No'),
        'realisation_date':fields.date('Realisation Date'),
        'cheque_status': fields.selection([('realised','Realised'),('bounced','Cheque Bounced')],'Cheque Status')
    }

1 个答案:

答案 0 :(得分:1)

该领域"总计"提交函数未正确声明。 我错过了声明多个'总和' 在collectiondetails.py中,我们需要将其声明为

'总计&#39 ;: fields.function(_total_amount,string =' Total',multi =' sums',help ="总金额可以使用收集表收集是")