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
1=== modified file 'account/account_move_line.py'
2--- account/account_move_line.py 2011-07-11 22:23:50 +0000
3+++ account/account_move_line.py 2011-07-13 11:03:39 +0000
4@@ -588,10 +588,18 @@
5 return False
6 return True
7
8+ def _check_date(self, cr, uid, ids, context=None):
9+ for l in self.browse(cr, uid, ids, context=context):
10+ if l.journal_id.allow_date:
11+ 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'):
12+ return False
13+ return True
14+
15 _constraints = [
16 (_check_no_view, 'You can not create move line on view account.', ['account_id']),
17 (_check_no_closed, 'You can not create move line on closed account.', ['account_id']),
18 (_check_company_id, 'Company must be same for its related account and period.',['company_id'] ),
19+ (_check_date, 'The date of your Journal Entry is not in the defined period!',['date'] ),
20 ]
21
22 #TODO: ONCHANGE_ACCOUNT_ID: set account_tax_id
23@@ -1098,35 +1106,6 @@
24 move_obj.validate(cr, uid, move_ids, context=context)
25 return result
26
27- def _check_date(self, cr, uid, vals, context=None, check=True):
28- if context is None:
29- context = {}
30- move_obj = self.pool.get('account.move')
31- journal_obj = self.pool.get('account.journal')
32- period_obj = self.pool.get('account.period')
33- journal_id = False
34- if 'date' in vals.keys():
35- if 'journal_id' in vals and 'journal_id' not in context:
36- journal_id = vals['journal_id']
37- if 'period_id' in vals and 'period_id' not in context:
38- period_id = vals['period_id']
39- elif 'journal_id' not in context and 'move_id' in vals:
40- if vals.get('move_id', False):
41- m = move_obj.browse(cr, uid, vals['move_id'])
42- journal_id = m.journal_id.id
43- period_id = m.period_id.id
44- else:
45- journal_id = context.get('journal_id', False)
46- period_id = context.get('period_id', False)
47- if journal_id:
48- journal = journal_obj.browse(cr, uid, journal_id, context=context)
49- if journal.allow_date and period_id:
50- period = period_obj.browse(cr, uid, period_id, context=context)
51- 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'):
52- raise osv.except_osv(_('Error'),_('The date of your Journal Entry is not in the defined period!'))
53- else:
54- return True
55-
56 def write(self, cr, uid, ids, vals, context=None, check=True, update_check=True):
57 if context is None:
58 context={}
59@@ -1137,7 +1116,6 @@
60 ids = [ids]
61 if vals.get('account_tax_id', False):
62 raise osv.except_osv(_('Unable to change tax !'), _('You can not change the tax, you should remove and recreate lines !'))
63- self._check_date(cr, uid, vals, context, check)
64 if ('account_id' in vals) and not account_obj.read(cr, uid, vals['account_id'], ['active'])['active']:
65 raise osv.except_osv(_('Bad account!'), _('You can not use an inactive account!'))
66 if update_check:
67@@ -1221,7 +1199,6 @@
68 company_id = self.pool.get('account.move').read(cr, uid, vals['move_id'], ['company_id']).get('company_id', False)
69 if company_id:
70 vals['company_id'] = company_id[0]
71- self._check_date(cr, uid, vals, context, check)
72 if ('account_id' in vals) and not account_obj.read(cr, uid, vals['account_id'], ['active'])['active']:
73 raise osv.except_osv(_('Bad account!'), _('You can not use an inactive account!'))
74 if 'journal_id' in vals:
75@@ -1232,7 +1209,6 @@
76 m = move_obj.browse(cr, uid, vals['move_id'])
77 context['journal_id'] = m.journal_id.id
78 context['period_id'] = m.period_id.id
79-
80 self._update_journal_check(cr, uid, context['journal_id'], context['period_id'], context)
81 move_id = vals.get('move_id', False)
82 journal = journal_obj.browse(cr, uid, context['journal_id'], context=context)

Subscribers

People subscribed via source and target branches

to all changes: