Help

Welcome!

This community is for professionals and enthusiasts of our products and services.
Share and discuss the best content and new marketing ideas, build your professional profile and become a better marketer together.

2

Calculate sum of customer payments

Avatar
Davronbek
2
1
7,475

in Odoo 8.0, I am trying to calculate the sum of payments made by a customer according to the customer's id. I wrote the following code but this hasn't helped at all. If any suggestions or help, you are more than welcome

def _get_sum_invoices(self, cr, uid, ids, field_name, arg, context=None):
res = dict(map(lambda x: (x, 0), ids))
# The current user may not have access rights for sale orders
try:
for partner in self.browse(cr, uid, ids, context):
setOfInvoices = self.env['account.invoice'].search([('id', "in", partner.invoice_ids)])
total = 0
for invoice in setOfInvoices:
total += invoice.amount
res[partner.id] = total
except:
pass
return res

_columns = {
'sum_payments': fields.function(_get_sum_pay, string='# SUM', type='float'),
'total': fields.one2many('account.invoice', 'partner_id','Sum Of Payments')
}
Avatar
Davronbek
Avatar
Discard
1 Answer
0
Best Answer

Dear Davronbek,

The following code to get sum of payments made by a customer

from openerp import fields, model, api

class res_partner(models.Model):
    _inherit = 'res.partner'
    
    @api.one
    def _get_sum_payment(self):
        payment = self.env['account.voucher'].search([('partner_id','=', self.id),('type','=','payment')])        
        self.sum_payments = sum(item.amount for item in payment)
        
    sum_payments = fields.Float(string="# Sum", compute='_get_sum_payment')


Good luck!
Avatar
Leo Tran
Comment Share
Avatar
Leo Tran
Avatar
Discard

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

Q&A Forum Regulations

Forum Regulations

By using the FAQ Forum on ERPOnline.vn website, you unconditionally agree to the following terms:

    1. Q&A Forum is a discussion environment to support each other in Odoo/ERPOnline implementation, in the spirit of "community support community", with internet address at: https://www.erponline.vn/forum/hoi-dap-7

    2. You are thoroughly responsible for the content submitted by you.

    3. DO NOT use the Q&A Forum for any activities that violate Vietnamese law and International Conventions to which Vietnam is a participant.

    4. DO NOT post content that is offensive, defamatory, or discredits other individuals or legal entities.

    5. DO NOT post advertisements or advertising content.

    6. DO NOT post content that is not related to management software and ERP in general as well as OpenERP and ERPOnline.vn in particular.

    7. DO NOT post copyrighted content or content, materials, products protected by Intellectual Property law without the written consent of the author.

    8. DO NOT embed images from other websites.

    9. You agree that all options, solutions, answers in the Q&A section on ERPOnline.vn website are for reference only. ERPOnline.vn website will not be liable if you have any damage when applying the plans given in the Q&A section on ERPOnline.vn website.

These terms and conditions may be amended to suit reality at any time without prior notice.