Merge lp:~openerp-dev/openobject-addons/6.0-opw-5852-pso into lp:openobject-addons/6.0

Proposed by Priyesh (OpenERP)
Status: Merged
Merged at revision: 4742
Proposed branch: lp:~openerp-dev/openobject-addons/6.0-opw-5852-pso
Merge into: lp:openobject-addons/6.0
Diff against target: 77 lines (+19/-6)
2 files modified
account/account.py (+9/-2)
account_voucher/account_voucher.py (+10/-4)
To merge this branch: bzr merge lp:~openerp-dev/openobject-addons/6.0-opw-5852-pso
Reviewer Review Type Date Requested Status
Priyesh (OpenERP) (community) Needs Resubmitting
qdp (OpenERP) Needs Fixing
Jay Vora (Serpent Consulting Services) Pending
Review via email: mp+66682@code.launchpad.net

Description of the change

Hello,

Passed company in context during the Payment for Invoice the invoice in multi-company environment.
Improved find method of Period.

Thanks,
Priyesh

To post a comment you must log in.
Revision history for this message
qdp (OpenERP) (qdp) wrote :

i guess that may fail again on *creation* of invoice... isn't it?

review: Needs Fixing
Revision history for this message
Priyesh (OpenERP) (pso-openerp) wrote :

Hello Quentin,
Thank you for your feedback and time.
But, Can you please give me an example how it can fail ?

Thanks,
Priyesh

Revision history for this message
qdp (OpenERP) (qdp) wrote :

if you don't give the company_id in the context, then it may fail, and you're not giving any special context for the invoice validation.

Also, the key used in the context should be 'force_company', as it will be that key that will be used for ir.property fields treatment in v6.1

so what you should do is:
company_id = user.company_id.id
if context.get('force_company',False):
   company_id = context['company_id']

(where user is a browse_record of uid.

Thanks

Revision history for this message
Priyesh (OpenERP) (pso-openerp) wrote :

Hello Quentin,

Thanks for your suggestion.

I have added company of user in default to stop failing if context is not correctly set.

Thanks,
Priyesh

review: Needs Resubmitting

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'account/account.py'
2--- account/account.py 2011-07-20 07:16:13 +0000
3+++ account/account.py 2011-08-02 13:03:38 +0000
4@@ -907,10 +907,17 @@
5 return False
6
7 def find(self, cr, uid, dt=None, context=None):
8+ if context is None: context = {}
9 if not dt:
10 dt = time.strftime('%Y-%m-%d')
11 #CHECKME: shouldn't we check the state of the period?
12- ids = self.search(cr, uid, [('date_start','<=',dt),('date_stop','>=',dt)])
13+ args = [('date_start', '<=' ,dt), ('date_stop', '>=', dt)]
14+ if context.get('company_id', False):
15+ args.append(('company_id', '=', context['company_id']))
16+ else:
17+ company_id = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.id
18+ args.append(('company_id', '=', company_id))
19+ ids = self.search(cr, uid, args, context=context)
20 if not ids:
21 raise osv.except_osv(_('Error !'), _('No period defined for this date: %s !\nPlease create a fiscal year.')%dt)
22 return ids
23@@ -1374,7 +1381,7 @@
24 cr.execute('SELECT SUM(%s) FROM account_move_line WHERE move_id=%%s AND id!=%%s' % (mode,), (move.id, line_id2))
25 result = cr.fetchone()[0] or 0.0
26 cr.execute('update account_move_line set '+mode2+'=%s where id=%s', (result, line_id))
27-
28+
29 #adjust also the amount in currency if needed
30 cr.execute("select currency_id, sum(amount_currency) as amount_currency from account_move_line where move_id = %s and currency_id is not null group by currency_id", (move.id,))
31 for row in cr.dictfetchall():
32
33=== modified file 'account_voucher/account_voucher.py'
34--- account_voucher/account_voucher.py 2011-07-26 11:27:59 +0000
35+++ account_voucher/account_voucher.py 2011-08-02 13:03:38 +0000
36@@ -39,7 +39,10 @@
37 if context is None: context = {}
38 if context.get('period_id', False):
39 return context.get('period_id')
40- periods = self.pool.get('account.period').find(cr, uid)
41+ if context.get('invoice_id', False):
42+ company_id = self.pool.get('account.invoice').browse(cr, uid, context['invoice_id'], context=context).company_id.id
43+ context.update({'company_id': company_id})
44+ periods = self.pool.get('account.period').find(cr, uid, context=context)
45 return periods and periods[0] or False
46
47 def _get_journal(self, cr, uid, context=None):
48@@ -118,7 +121,7 @@
49 def fields_view_get(self, cr, uid, view_id=None, view_type=False, context=None, toolbar=False, submenu=False):
50 mod_obj = self.pool.get('ir.model.data')
51 if context is None: context = {}
52-
53+
54 def get_res_id(view_type, condition):
55 result = False
56 if view_type == 'tree':
57@@ -466,7 +469,7 @@
58 domain = [('state','=','valid'), ('account_id.type', '=', account_type), ('reconcile_id', '=', False), ('partner_id', '=', partner_id)]
59 if context.get('invoice_id', False):
60 domain.append(('invoice', '=', context['invoice_id']))
61- ids = move_line_pool.search(cr, uid, domain, context=context)
62+ ids = move_line_pool.search(cr, uid, domain, context=context)
63 else:
64 ids = context['move_line_ids']
65 ids.reverse()
66@@ -535,7 +538,10 @@
67 """
68 period_pool = self.pool.get('account.period')
69 res = self.onchange_partner_id(cr, uid, ids, partner_id, journal_id, price, currency_id, ttype, date, context=context)
70- pids = period_pool.search(cr, uid, [('date_start', '<=', date), ('date_stop', '>=', date)])
71+ if context.get('invoice_id', False):
72+ company_id = self.pool.get('account.invoice').browse(cr, uid, context['invoice_id'], context=context).company_id.id
73+ context.update({'company_id': company_id})
74+ pids = period_pool.find(cr, uid, date, context=context)
75 if pids:
76 if not 'value' in res:
77 res['value'] = {}