Merge lp:~unifield-team/unifield-server/us-932 into lp:unifield-server

Proposed by jftempo
Status: Merged
Merged at revision: 3755
Proposed branch: lp:~unifield-team/unifield-server/us-932
Merge into: lp:unifield-server
Diff against target: 120 lines (+77/-3)
1 file modified
bin/addons/account_override/account.py (+77/-3)
To merge this branch: bzr merge lp:~unifield-team/unifield-server/us-932
Reviewer Review Type Date Requested Status
UniField Reviewer Team Pending
Review via email: mp+295154@code.launchpad.net
To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/addons/account_override/account.py'
2--- bin/addons/account_override/account.py 2016-03-23 09:07:28 +0000
3+++ bin/addons/account_override/account.py 2016-05-19 07:06:12 +0000
4@@ -797,8 +797,59 @@
5 """
6 Check that we can write on this if we come from web menu or synchronisation.
7 """
8- if not context:
9+ def check_update_sequence(rec, new_journal_id, new_period_id):
10+ """
11+ returns new sequence move vals (sequence_id, name) or None
12+ :rtype : dict/None
13+ """
14+ if m.state != 'draft':
15+ return None
16+
17+ period_obj = self.pool.get('account.period')
18+ period_rec = False
19+ do_update = False
20+
21+ # journal or FY has changed ?
22+ if new_journal_id and m.journal_id.id != new_journal_id:
23+ do_update = True
24+ if new_period_id and m.period_id.id != new_period_id:
25+ period_rec = period_obj.browse(cr, uid, new_period_id)
26+ do_update = period_rec.fiscalyear_id.id \
27+ != m.period_id.fiscalyear_id.id # FY changed
28+ if not do_update:
29+ return None
30+
31+ # get instance and journal/period
32+ instance_rec = self.pool.get('res.users').browse(cr, uid, uid,
33+ context).company_id.instance_id
34+ if not instance_rec.move_prefix:
35+ raise osv.except_osv(_('Warning'),
36+ _('No move prefix found for this instance!' \
37+ ' Please configure it on Company view.'))
38+ journal_rec = self.pool.get('account.journal').browse(cr, uid,
39+ new_journal_id or m.journal_id.id)
40+ period_rec = period_rec or m.period_id
41+ if period_rec.state == 'created':
42+ raise osv.except_osv(_('Error !'),
43+ _("Period '%s' is not open!' \
44+ ' No Journal Entry is updated") % (period_rec.name, ))
45+
46+ # get new sequence number and return related vals
47+ sequence_number = self.pool.get('ir.sequence').get_id(
48+ cr, uid, journal_rec.sequence_id.id,
49+ context={ 'fiscalyear_id': period_rec.fiscalyear_id.id })
50+ if instance_rec and journal_rec and sequence_number:
51+ return {
52+ 'sequence_id': journal_rec.sequence_id.id,
53+ 'name': "%s-%s-%s" % (instance_rec.move_prefix,
54+ journal_rec.code, sequence_number, ),
55+ }
56+ return None
57+
58+ if context is None:
59 context = {}
60+ new_sequence_vals_by_move_id = {}
61+
62 if context.get('from_web_menu', False) or context.get('sync_update_execution', False):
63 # by default, from synchro, we just need to update period_id and journal_id
64 fields = ['journal_id', 'period_id']
65@@ -811,6 +862,20 @@
66 raise osv.except_osv(_('Warning'), _('You cannot edit a Journal Entry created by the system.'))
67 if m.journal_id.type == 'system':
68 raise osv.except_osv(_('Warning'), _('You can not edit a Journal Entry on a system journal'))
69+
70+ if context.get('from_web_menu', False) \
71+ and not context.get('sync_update_execution', False):
72+ # US-932: journal or FY changed ?
73+ # typical UC: manual JE from UI: journal/period changed
74+ # after a duplicate.
75+ # check sequence and update it if needed. (we do not update
76+ # it during on_change() to prevent sequence jumps)
77+ new_seq = check_update_sequence(m,
78+ vals.get('journal_id', False),
79+ vals.get('period_id', False))
80+ if new_seq:
81+ new_sequence_vals_by_move_id[m.id] = new_seq
82+
83 # Update context in order journal item could retrieve this @creation
84 # Also update some other fields
85 ml_vals = {}
86@@ -818,15 +883,24 @@
87 if el in vals:
88 context[el] = vals.get(el)
89 ml_vals.update({el: vals.get(el)})
90+
91 # UFTP-262: For manual_name (description on account.move), update "name" on account.move.line
92 if 'manual_name' in vals:
93 ml_vals.update({'name': vals.get('manual_name', '')})
94+
95 # Update document date AND date at the same time
96 if ml_vals:
97 ml_id_list = [ml.id for ml in m.line_id]
98 self.pool.get('account.move.line').write(cr, uid,
99 ml_id_list, ml_vals, context, False, False)
100- res = super(account_move, self).write(cr, uid, ids, vals, context=context)
101+
102+ res = super(account_move, self).write(cr, uid, ids, vals,
103+ context=context)
104+ if new_sequence_vals_by_move_id:
105+ for id in new_sequence_vals_by_move_id:
106+ osv.osv.write(self, cr, uid, id,
107+ new_sequence_vals_by_move_id[id], context=context) # US-932
108+
109 self._check_document_date(cr, uid, ids, context)
110 self._check_date_in_period(cr, uid, ids, context)
111 return res
112@@ -888,7 +962,7 @@
113 'state': 'draft',
114 'document_date': je.document_date,
115 'date': je.date,
116- 'name': ''
117+ 'name': '',
118 }
119 res = super(account_move, self).copy(cr, uid, a_id, vals, context=context)
120 for line in je.line_id:

Subscribers

People subscribed via source and target branches

to all changes: