Merge lp:~openerp-community/openobject-addons/6.0_bug_801562 into lp:openobject-addons/6.0

Proposed by Leonardo Pistone
Status: Needs review
Proposed branch: lp:~openerp-community/openobject-addons/6.0_bug_801562
Merge into: lp:openobject-addons/6.0
Diff against target: 22 lines (+3/-1)
1 file modified
account/report/account_partner_ledger.py (+3/-1)
To merge this branch: bzr merge lp:~openerp-community/openobject-addons/6.0_bug_801562
Reviewer Review Type Date Requested Status
Amit Dodiya (OpenERP) (community) Needs Fixing
OpenERP Core Team Pending
Review via email: mp+65792@code.launchpad.net

Description of the change

That _should_ make the partner ledge word on multi-company scenarios.

To post a comment you must log in.
Revision history for this message
Amit Dodiya (OpenERP) (ado-openerp) wrote :

Leonardo,

I am sorry, but this does not look a better approach.
Instead, it will give a wrong report because you will only search move lines with company=user's company. Here, it would be possible that the transaction wof user's company has different partner on mpve line,which just happened to me.

You should search partner_id's company = user's company.

I prefer this piece of code:
=== modified file 'account/report/account_partner_ledger.py'
--- account/report/account_partner_ledger.py 2011-01-14 00:11:01 +0000
+++ account/report/account_partner_ledger.py 2011-06-30 10:20:09 +0000
@@ -59,6 +59,8 @@
         self.query = obj_move._query_get(self.cr, self.uid, obj='l', context=data['form'].get('used_context', {}))
         ctx2 = data['form'].get('used_context',{}).copy()
         ctx2.update({'initial_bal': True})
+ current_company = self.pool.get('res.users').browse(self.cr, self.uid, self.uid).company_id.id
+ valid_partners = obj_partner.search(self.cr, self.uid, [('company_id','=',current_company)])
         self.init_query = obj_move._query_get(self.cr, self.uid, obj='l', context=ctx2)
         self.reconcil = data['form'].get('reconcil', True)
         self.initial_balance = data['form'].get('initial_balance', True)
@@ -69,7 +71,6 @@
         move_state = ['draft','posted']
         if self.target_move == 'posted':
             move_state = ['posted']
-
         if (data['model'] == 'res.partner'):
             ## Si on imprime depuis les partenaires
             if ids:
@@ -101,12 +102,13 @@
 # "AND " + self.query +" " \
                     "AND l.account_id IN %s " \
                     " " + PARTNER_REQUEST + " " \
- "AND account.active ",
+ "AND account.active",
                 (tuple(move_state), tuple(self.account_ids),))

         res = self.cr.dictfetchall()
         for res_line in res:
- partner_to_use.append(res_line['partner_id'])
+ if res_line['partner_id'] in valid_partners:
+ partner_to_use.append(res_line['partner_id'])
         new_ids = partner_to_use
         self.partner_ids = new_ids
         objects = obj_partner.browse(self.cr, self.uid, new_ids)

Hope this helps.

review: Needs Fixing
Revision history for this message
Leonardo Pistone (lepistone) wrote :

Amit,

thanks for your reply.

I don't get your point, about which is exactly the situation that wouldn't be covered by my fix but would be covered by yours.

Can you please explain that to me again?

Thanks a lot

Unmerged revisions

4675. By Leonardo Pistone

[FIX] multi-company partner ledger

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'account/report/account_partner_ledger.py'
2--- account/report/account_partner_ledger.py 2011-01-14 00:11:01 +0000
3+++ account/report/account_partner_ledger.py 2011-06-24 13:52:35 +0000
4@@ -56,6 +56,7 @@
5 def set_context(self, objects, data, ids, report_type=None):
6 obj_move = self.pool.get('account.move.line')
7 obj_partner = self.pool.get('res.partner')
8+ current_company = self.pool.get('res.users').browse(self.cr, self.uid, self.uid).company_id.id
9 self.query = obj_move._query_get(self.cr, self.uid, obj='l', context=data['form'].get('used_context', {}))
10 ctx2 = data['form'].get('used_context',{}).copy()
11 ctx2.update({'initial_bal': True})
12@@ -101,8 +102,9 @@
13 # "AND " + self.query +" " \
14 "AND l.account_id IN %s " \
15 " " + PARTNER_REQUEST + " " \
16+ "AND l.company_id = %s " \
17 "AND account.active ",
18- (tuple(move_state), tuple(self.account_ids),))
19+ (tuple(move_state), tuple(self.account_ids), current_company))
20
21 res = self.cr.dictfetchall()
22 for res_line in res: