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
=== modified file 'account/account_move_line.py'
--- account/account_move_line.py 2011-11-22 10:49:26 +0000
+++ account/account_move_line.py 2011-12-06 06:46:27 +0000
@@ -590,11 +590,19 @@
590 if l.company_id != l.account_id.company_id or l.company_id != l.period_id.company_id:590 if l.company_id != l.account_id.company_id or l.company_id != l.period_id.company_id:
591 return False591 return False
592 return True592 return True
593
594 def _check_date(self, cr, uid, ids, context=None):
595 for line in self.browse(cr, uid, ids, context=context):
596 if line.journal_id.allow_date:
597 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'):
598 return False
599 return True
593600
594 _constraints = [601 _constraints = [
595 (_check_no_view, 'You can not create move line on view account.', ['account_id']),602 (_check_no_view, 'You can not create move line on view account.', ['account_id']),
596 (_check_no_closed, 'You can not create move line on closed account.', ['account_id']),603 (_check_no_closed, 'You can not create move line on closed account.', ['account_id']),
597 (_check_company_id, 'Company must be same for its related account and period.',['company_id'] ),604 (_check_company_id, 'Company must be same for its related account and period.',['company_id'] ),
605 (_check_date, 'The date of your Journal Entry is not in the defined period!', ['date']),
598 ]606 ]
599607
600 #TODO: ONCHANGE_ACCOUNT_ID: set account_tax_id608 #TODO: ONCHANGE_ACCOUNT_ID: set account_tax_id
@@ -1099,35 +1107,6 @@
1099 move_obj.validate(cr, uid, [line.move_id.id], context=context)1107 move_obj.validate(cr, uid, [line.move_id.id], context=context)
1100 return result1108 return result
11011109
1102 def _check_date(self, cr, uid, vals, context=None, check=True):
1103 if context is None:
1104 context = {}
1105 move_obj = self.pool.get('account.move')
1106 journal_obj = self.pool.get('account.journal')
1107 period_obj = self.pool.get('account.period')
1108 journal_id = False
1109 if 'date' in vals.keys():
1110 if 'journal_id' in vals and 'journal_id' not in context:
1111 journal_id = vals['journal_id']
1112 if 'period_id' in vals and 'period_id' not in context:
1113 period_id = vals['period_id']
1114 elif 'journal_id' not in context and 'move_id' in vals:
1115 if vals.get('move_id', False):
1116 m = move_obj.browse(cr, uid, vals['move_id'])
1117 journal_id = m.journal_id.id
1118 period_id = m.period_id.id
1119 else:
1120 journal_id = context.get('journal_id', False)
1121 period_id = context.get('period_id', False)
1122 if journal_id:
1123 journal = journal_obj.browse(cr, uid, journal_id, context=context)
1124 if journal.allow_date and period_id:
1125 period = period_obj.browse(cr, uid, period_id, context=context)
1126 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'):
1127 raise osv.except_osv(_('Error'),_('The date of your Journal Entry is not in the defined period!'))
1128 else:
1129 return True
1130
1131 def write(self, cr, uid, ids, vals, context=None, check=True, update_check=True):1110 def write(self, cr, uid, ids, vals, context=None, check=True, update_check=True):
1132 if context is None:1111 if context is None:
1133 context={}1112 context={}
@@ -1136,7 +1115,6 @@
1136 journal_obj = self.pool.get('account.journal')1115 journal_obj = self.pool.get('account.journal')
1137 if vals.get('account_tax_id', False):1116 if vals.get('account_tax_id', False):
1138 raise osv.except_osv(_('Unable to change tax !'), _('You can not change the tax, you should remove and recreate lines !'))1117 raise osv.except_osv(_('Unable to change tax !'), _('You can not change the tax, you should remove and recreate lines !'))
1139 self._check_date(cr, uid, vals, context, check)
1140 if ('account_id' in vals) and not account_obj.read(cr, uid, vals['account_id'], ['active'])['active']:1118 if ('account_id' in vals) and not account_obj.read(cr, uid, vals['account_id'], ['active'])['active']:
1141 raise osv.except_osv(_('Bad account!'), _('You can not use an inactive account!'))1119 raise osv.except_osv(_('Bad account!'), _('You can not use an inactive account!'))
1142 if update_check:1120 if update_check:
@@ -1219,7 +1197,6 @@
1219 company_id = self.pool.get('account.move').read(cr, uid, vals['move_id'], ['company_id']).get('company_id', False)1197 company_id = self.pool.get('account.move').read(cr, uid, vals['move_id'], ['company_id']).get('company_id', False)
1220 if company_id:1198 if company_id:
1221 vals['company_id'] = company_id[0]1199 vals['company_id'] = company_id[0]
1222 self._check_date(cr, uid, vals, context, check)
1223 if ('account_id' in vals) and not account_obj.read(cr, uid, vals['account_id'], ['active'])['active']:1200 if ('account_id' in vals) and not account_obj.read(cr, uid, vals['account_id'], ['active'])['active']:
1224 raise osv.except_osv(_('Bad account!'), _('You can not use an inactive account!'))1201 raise osv.except_osv(_('Bad account!'), _('You can not use an inactive account!'))
1225 if 'journal_id' in vals:1202 if 'journal_id' in vals: