Reputation: 266
I have a custom module in i'm collecting details of the payment.I've created the fields and UI as i want.Now there is a field "amount" in one2many Field,i need sum of all "amounts" and store them in other field "total" when i save the form. In collectiondeatils.py , "payment_collection_details" is one2many field.Amount is a field related to "class payment.collection.details".Now on click of save i should give the sum of amount to "Total" field which is present in collectiondetails.py. On click of save button in img1 i'm getting an error which is in img2
Error : " Uncaught Error: [_.sprintf] expecting number but found object"
![Img1][1]
![img2][2]
[1]: https://i.sstatic.net/673h1.png
[2]: https://i.sstatic.net/oiVYJ.png
My Code :
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')
}
Upvotes: 1
Views: 1424
Reputation: 266
The field "total" which is filed function is not declared properlly. I missed declaring multi='sums' In collectiondetails.py we need to declare it as
'total': fields.function(_total_amount,string='Total',multi='sums',help="Total amount that can be collected using collection table is")
Upvotes: 1