Merge lp:~openerp-dev/openobject-addons/trunk-bug-783994-ara into lp:openobject-addons

Proposed by Ashvin Rathod (OpenERP)
Status: Merged
Merged at revision: 4994
Proposed branch: lp:~openerp-dev/openobject-addons/trunk-bug-783994-ara
Merge into: lp:openobject-addons
Diff against target: 82 lines (+8/-32)
1 file modified
account/account_move_line.py (+8/-32)
To merge this branch: bzr merge lp:~openerp-dev/openobject-addons/trunk-bug-783994-ara
Reviewer Review Type Date Requested Status
Mustufa Rangwala (Open ERP) (community) Approve
Ashvin Rathod (OpenERP) (community) Needs Resubmitting
qdp (OpenERP) Needs Fixing
Review via email: mp+61545@code.launchpad.net

Description of the change

Hello,

Fix: account_move_line: uninitialized period_id

Thanks,
ara

To post a comment you must log in.
Revision history for this message
Mustufa Rangwala (Open ERP) (mra-tinyerp) wrote :

Hello,

Yes we are getting period_id in vals and we should use it.
so defining period_id at begining of the method seems ok but at the time of condition:

journal = journal_obj.browse(cr, uid, journal_id, context=context)
if journal.allow_date and period_id:

we should use period_id from vals.

thanks,
mra

review: Needs Fixing
Revision history for this message
Ashvin Rathod (OpenERP) (ara-tinyerp) wrote :

Hello,

I have made change as per suggestion.

Thanks,
ara

review: Needs Resubmitting
Revision history for this message
qdp (OpenERP) (qdp) wrote :

please put the _check_date constraint into the attribute _constraints of account.move.line.

review: Needs Fixing
Revision history for this message
Ashvin Rathod (OpenERP) (ara-tinyerp) wrote :

Hello,

I have made changes as per suggestion.

Thanks,
ara

review: Needs Resubmitting
Revision history for this message
Mustufa Rangwala (Open ERP) (mra-tinyerp) wrote :

- Remove if context is None .. condition as context is not used in the definition.
- + lines = self.browse(cr, uid, ids, context=context)
 + for l in lines:

you can merge above two lines

review: Needs Fixing
Revision history for this message
Ashvin Rathod (OpenERP) (ara-tinyerp) wrote :

Hello,

I have changed as per suggestion.

Thanks,
ara

review: Needs Resubmitting
Revision history for this message
Mustufa Rangwala (Open ERP) (mra-tinyerp) :
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-07-11 22:23:50 +0000
+++ account/account_move_line.py 2011-07-13 11:03:39 +0000
@@ -588,10 +588,18 @@
588 return False588 return False
589 return True589 return True
590590
591 def _check_date(self, cr, uid, ids, context=None):
592 for l in self.browse(cr, uid, ids, context=context):
593 if l.journal_id.allow_date:
594 if not time.strptime(l.date[:10],'%Y-%m-%d') >= time.strptime(l.period_id.date_start, '%Y-%m-%d') or not time.strptime(l.date[:10], '%Y-%m-%d') <= time.strptime(l.period_id.date_stop, '%Y-%m-%d'):
595 return False
596 return True
597
591 _constraints = [598 _constraints = [
592 (_check_no_view, 'You can not create move line on view account.', ['account_id']),599 (_check_no_view, 'You can not create move line on view account.', ['account_id']),
593 (_check_no_closed, 'You can not create move line on closed account.', ['account_id']),600 (_check_no_closed, 'You can not create move line on closed account.', ['account_id']),
594 (_check_company_id, 'Company must be same for its related account and period.',['company_id'] ),601 (_check_company_id, 'Company must be same for its related account and period.',['company_id'] ),
602 (_check_date, 'The date of your Journal Entry is not in the defined period!',['date'] ),
595 ]603 ]
596604
597 #TODO: ONCHANGE_ACCOUNT_ID: set account_tax_id605 #TODO: ONCHANGE_ACCOUNT_ID: set account_tax_id
@@ -1098,35 +1106,6 @@
1098 move_obj.validate(cr, uid, move_ids, context=context)1106 move_obj.validate(cr, uid, move_ids, context=context)
1099 return result1107 return result
11001108
1101 def _check_date(self, cr, uid, vals, context=None, check=True):
1102 if context is None:
1103 context = {}
1104 move_obj = self.pool.get('account.move')
1105 journal_obj = self.pool.get('account.journal')
1106 period_obj = self.pool.get('account.period')
1107 journal_id = False
1108 if 'date' in vals.keys():
1109 if 'journal_id' in vals and 'journal_id' not in context:
1110 journal_id = vals['journal_id']
1111 if 'period_id' in vals and 'period_id' not in context:
1112 period_id = vals['period_id']
1113 elif 'journal_id' not in context and 'move_id' in vals:
1114 if vals.get('move_id', False):
1115 m = move_obj.browse(cr, uid, vals['move_id'])
1116 journal_id = m.journal_id.id
1117 period_id = m.period_id.id
1118 else:
1119 journal_id = context.get('journal_id', False)
1120 period_id = context.get('period_id', False)
1121 if journal_id:
1122 journal = journal_obj.browse(cr, uid, journal_id, context=context)
1123 if journal.allow_date and period_id:
1124 period = period_obj.browse(cr, uid, period_id, context=context)
1125 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'):
1126 raise osv.except_osv(_('Error'),_('The date of your Journal Entry is not in the defined period!'))
1127 else:
1128 return True
1129
1130 def write(self, cr, uid, ids, vals, context=None, check=True, update_check=True):1109 def write(self, cr, uid, ids, vals, context=None, check=True, update_check=True):
1131 if context is None:1110 if context is None:
1132 context={}1111 context={}
@@ -1137,7 +1116,6 @@
1137 ids = [ids]1116 ids = [ids]
1138 if vals.get('account_tax_id', False):1117 if vals.get('account_tax_id', False):
1139 raise osv.except_osv(_('Unable to change tax !'), _('You can not change the tax, you should remove and recreate lines !'))1118 raise osv.except_osv(_('Unable to change tax !'), _('You can not change the tax, you should remove and recreate lines !'))
1140 self._check_date(cr, uid, vals, context, check)
1141 if ('account_id' in vals) and not account_obj.read(cr, uid, vals['account_id'], ['active'])['active']:1119 if ('account_id' in vals) and not account_obj.read(cr, uid, vals['account_id'], ['active'])['active']:
1142 raise osv.except_osv(_('Bad account!'), _('You can not use an inactive account!'))1120 raise osv.except_osv(_('Bad account!'), _('You can not use an inactive account!'))
1143 if update_check:1121 if update_check:
@@ -1221,7 +1199,6 @@
1221 company_id = self.pool.get('account.move').read(cr, uid, vals['move_id'], ['company_id']).get('company_id', False)1199 company_id = self.pool.get('account.move').read(cr, uid, vals['move_id'], ['company_id']).get('company_id', False)
1222 if company_id:1200 if company_id:
1223 vals['company_id'] = company_id[0]1201 vals['company_id'] = company_id[0]
1224 self._check_date(cr, uid, vals, context, check)
1225 if ('account_id' in vals) and not account_obj.read(cr, uid, vals['account_id'], ['active'])['active']:1202 if ('account_id' in vals) and not account_obj.read(cr, uid, vals['account_id'], ['active'])['active']:
1226 raise osv.except_osv(_('Bad account!'), _('You can not use an inactive account!'))1203 raise osv.except_osv(_('Bad account!'), _('You can not use an inactive account!'))
1227 if 'journal_id' in vals:1204 if 'journal_id' in vals:
@@ -1232,7 +1209,6 @@
1232 m = move_obj.browse(cr, uid, vals['move_id'])1209 m = move_obj.browse(cr, uid, vals['move_id'])
1233 context['journal_id'] = m.journal_id.id1210 context['journal_id'] = m.journal_id.id
1234 context['period_id'] = m.period_id.id1211 context['period_id'] = m.period_id.id
1235
1236 self._update_journal_check(cr, uid, context['journal_id'], context['period_id'], context)1212 self._update_journal_check(cr, uid, context['journal_id'], context['period_id'], context)
1237 move_id = vals.get('move_id', False)1213 move_id = vals.get('move_id', False)
1238 journal = journal_obj.browse(cr, uid, context['journal_id'], context=context)1214 journal = journal_obj.browse(cr, uid, context['journal_id'], context=context)

Subscribers

People subscribed via source and target branches

to all changes: