res_partner.credit and debit do not always return correct values

Bug #1066066 reported by Ferdinand
14
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Odoo Addons (MOVED TO GITHUB)
Confirmed
Low
OpenERP R&D Addons Team 3

Bug Description

for line in account_move_line_obj.browse(cr, uid, ids) :

line.partner_id.credit is always 0

line.partner_id.debit
          positive value => credit
          negative value => debit

Tags: invoicing
Revision history for this message
Amit Parik (amit-parik) wrote :

Hello DR Ferdinand,

Would you please elaborate more on this issue. Please provide a usecase/ steps to reproduce it.

Thanks and waiting for your reply!

Changed in openobject-addons:
status: New → Incomplete
Revision history for this message
Ferdinand (office-chricar) wrote :

the formula as programmed only works if called as function field from res_partner.

if called "stand alone" it returns wrong values as described

    def _credit_debit_get(self, cr, uid, ids, field_names, arg, context=None):
        query = self.pool.get('account.move.line')._query_get(cr, uid, context=context)
        cr.execute("""SELECT l.partner_id, a.type, SUM(l.debit-l.credit)
                      FROM account_move_line l
                      LEFT JOIN account_account a ON (l.account_id=a.id)
                      WHERE a.type IN ('receivable','payable')
                      AND l.partner_id IN %s
                      AND l.reconcile_id IS NULL
                      AND """ + query + """
                      GROUP BY l.partner_id, a.type
                      """,
                   (tuple(ids),))
        maps = {'receivable':'credit', 'payable':'debit' }
        res = {}
        for id in ids:
            res[id] = {}.fromkeys(field_names, 0)
        for pid,type,val in cr.fetchall():
            if val is None: val=0
            res[pid][maps[type]] = (type=='receivable') and val or -val
        return res

affects: openobject-addons → openobject-server
Changed in openobject-server:
status: Incomplete → New
affects: openobject-server → openobject-addons
Changed in openobject-addons:
assignee: nobody → OpenERP R&D Addons Team 3 (openerp-dev-addons3)
importance: Undecided → Low
status: New → Confirmed
Revision history for this message
Ferdinand (office-chricar) wrote :

please wrong values in accounting is not "low" priority

Changed in openobject-addons:
importance: Low → Medium
Revision history for this message
Josse Colpaert (OpenERP) (jco-openerp) wrote :

Normally this can not be the case as you can see the field credit in the partner form under the Accounting tab (Total Receivable). E.g. when you create customer invoices and validate them (leave open), this field will be positive.

Are you sure to be taking all the account move lines?

Revision history for this message
Ferdinand (office-chricar) wrote :

yes

the code is in
http://bazaar.launchpad.net/~c2c/c2c-rd-addons/6.1/files/head:/c2c_account_payment_extension/

./c2c_account_payment_extension/wizard/account_payment_order.py

~line 105

pls look also at
 https://bugs.launchpad.net/openobject-addons/+bug/1066066

Revision history for this message
Josse Colpaert (OpenERP) (jco-openerp) wrote :

Dear Ferdinand,

In your domain, the account type is payable. This should be receivable for move lines with credits, which will give you the partners with credit > 0 for sure.

domain = \
            [ ('reconcile_id', '=', False)
            , ('account_id.type', '=', 'payable')
            , ('company_id', '=', company_id)
            , ('partner_id', '!=', False) # must be there in case there are imported lines without partner_id (Deloitte)
            , ('state', '=', 'valid')
            # , ('amount_to_pay', '>', 0) # see later in if statements
            ]

Revision history for this message
Ferdinand (office-chricar) wrote :

unfortunately your assumption is not true

on a payable account there are sometimes debit (partial payments and down payments) AND credit moves

Revision history for this message
Josse Colpaert (OpenERP) (jco-openerp) wrote :

Indeed, credit is Total Receivable and debit Total Payable.

Revision history for this message
Ferdinand (office-chricar) wrote :

can we please agree that this is wrong ?

Revision history for this message
Josse Colpaert (OpenERP) (jco-openerp) wrote :

You are right that the name of the field is not logical (credit, debit). The label of the field (string="Total Receivable") however is. We are a little more careful in changing the names of the fields themselves, certainly at a short time before a release and would like to wait the appropriate time for changing it .

Changed in openobject-addons:
importance: Medium → Low
Amit Parik (amit-parik)
tags: added: invoicing
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.