Merge lp:~openerp-dev/openobject-addons/6.0-opw-50934-ado into lp:openobject-addons/6.0

Proposed by Amit Dodiya (OpenERP)
Status: Merged
Merge reported by: nel
Merged at revision: not available
Proposed branch: lp:~openerp-dev/openobject-addons/6.0-opw-50934-ado
Merge into: lp:openobject-addons/6.0
Diff against target: 75 lines (+8/-31)
1 file modified
account/account_move_line.py (+8/-31)
To merge this branch: bzr merge lp:~openerp-dev/openobject-addons/6.0-opw-50934-ado
Reviewer Review Type Date Requested Status
Priyesh (OpenERP) (community) Approve
Amit Dodiya (OpenERP) (community) Needs Resubmitting
Review via email: mp+84565@code.launchpad.net

Description of the change

Hello,

[FIX] : UnboundLocalError: local variable 'period_id' referenced before assignment while creating a journal items.

6.0 series with demo data and gtk client

1). Accounting > Configuration > Journals > Purchase Journal
2). Enable "check date not in period" (this is important to reproduce the bug)
3). Account > Journal Items > New
4). in the new line:
  * select any account
  * name = /
  * journal = Purchase Journal
5). click Save and you get the stack trace below

Code is back-ported from trunk.

Thanks,
Amit

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

Hello Amit,

Code is working as per expectation but take care while using var name.
You can use 'line' instead of using 'l'.

Thanks for the fix,
Priyesh

review: Needs Fixing
4945. By Amit Dodiya (OpenERP)

 [FIX] account_move_line: uninitialized period_id

Revision history for this message
Amit Dodiya (OpenERP) (ado-openerp) wrote :

Hello,

I have changed the variable name as per the suggestion.

Thanks,
Amit

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

Hello Amit,

Thanks for your quick fix,
Priyesh

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'account/account_move_line.py'
2--- account/account_move_line.py 2011-11-22 10:49:26 +0000
3+++ account/account_move_line.py 2011-12-06 06:46:27 +0000
4@@ -590,11 +590,19 @@
5 if l.company_id != l.account_id.company_id or l.company_id != l.period_id.company_id:
6 return False
7 return True
8+
9+ def _check_date(self, cr, uid, ids, context=None):
10+ for line in self.browse(cr, uid, ids, context=context):
11+ if line.journal_id.allow_date:
12+ if not time.strptime(line.date[:10],'%Y-%m-%d') >= time.strptime(line.period_id.date_start, '%Y-%m-%d') or not time.strptime(line.date[:10], '%Y-%m-%d') <= time.strptime(line.period_id.date_stop, '%Y-%m-%d'):
13+ return False
14+ return True
15
16 _constraints = [
17 (_check_no_view, 'You can not create move line on view account.', ['account_id']),
18 (_check_no_closed, 'You can not create move line on closed account.', ['account_id']),
19 (_check_company_id, 'Company must be same for its related account and period.',['company_id'] ),
20+ (_check_date, 'The date of your Journal Entry is not in the defined period!', ['date']),
21 ]
22
23 #TODO: ONCHANGE_ACCOUNT_ID: set account_tax_id
24@@ -1099,35 +1107,6 @@
25 move_obj.validate(cr, uid, [line.move_id.id], context=context)
26 return result
27
28- def _check_date(self, cr, uid, vals, context=None, check=True):
29- if context is None:
30- context = {}
31- move_obj = self.pool.get('account.move')
32- journal_obj = self.pool.get('account.journal')
33- period_obj = self.pool.get('account.period')
34- journal_id = False
35- if 'date' in vals.keys():
36- if 'journal_id' in vals and 'journal_id' not in context:
37- journal_id = vals['journal_id']
38- if 'period_id' in vals and 'period_id' not in context:
39- period_id = vals['period_id']
40- elif 'journal_id' not in context and 'move_id' in vals:
41- if vals.get('move_id', False):
42- m = move_obj.browse(cr, uid, vals['move_id'])
43- journal_id = m.journal_id.id
44- period_id = m.period_id.id
45- else:
46- journal_id = context.get('journal_id', False)
47- period_id = context.get('period_id', False)
48- if journal_id:
49- journal = journal_obj.browse(cr, uid, journal_id, context=context)
50- if journal.allow_date and period_id:
51- period = period_obj.browse(cr, uid, period_id, context=context)
52- if not time.strptime(vals['date'][:10],'%Y-%m-%d') >= time.strptime(period.date_start, '%Y-%m-%d') or not time.strptime(vals['date'][:10], '%Y-%m-%d') <= time.strptime(period.date_stop, '%Y-%m-%d'):
53- raise osv.except_osv(_('Error'),_('The date of your Journal Entry is not in the defined period!'))
54- else:
55- return True
56-
57 def write(self, cr, uid, ids, vals, context=None, check=True, update_check=True):
58 if context is None:
59 context={}
60@@ -1136,7 +1115,6 @@
61 journal_obj = self.pool.get('account.journal')
62 if vals.get('account_tax_id', False):
63 raise osv.except_osv(_('Unable to change tax !'), _('You can not change the tax, you should remove and recreate lines !'))
64- self._check_date(cr, uid, vals, context, check)
65 if ('account_id' in vals) and not account_obj.read(cr, uid, vals['account_id'], ['active'])['active']:
66 raise osv.except_osv(_('Bad account!'), _('You can not use an inactive account!'))
67 if update_check:
68@@ -1219,7 +1197,6 @@
69 company_id = self.pool.get('account.move').read(cr, uid, vals['move_id'], ['company_id']).get('company_id', False)
70 if company_id:
71 vals['company_id'] = company_id[0]
72- self._check_date(cr, uid, vals, context, check)
73 if ('account_id' in vals) and not account_obj.read(cr, uid, vals['account_id'], ['active'])['active']:
74 raise osv.except_osv(_('Bad account!'), _('You can not use an inactive account!'))
75 if 'journal_id' in vals: