Merge lp:~unifield-team/unifield-wm/us-773 into lp:unifield-wm

Proposed by jftempo
Status: Merged
Merged at revision: 2695
Proposed branch: lp:~unifield-team/unifield-wm/us-773
Merge into: lp:unifield-wm
Diff against target: 121 lines (+58/-12)
2 files modified
account_corrections/wizard/analytic_distribution_wizard.py (+15/-7)
analytic_distribution/analytic_line.py (+43/-5)
To merge this branch: bzr merge lp:~unifield-team/unifield-wm/us-773
Reviewer Review Type Date Requested Status
UniField Reviewer Team Pending
Review via email: mp+279549@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 'account_corrections/wizard/analytic_distribution_wizard.py'
2--- account_corrections/wizard/analytic_distribution_wizard.py 2015-11-26 16:41:44 +0000
3+++ account_corrections/wizard/analytic_distribution_wizard.py 2015-12-04 08:35:31 +0000
4@@ -347,20 +347,28 @@
5 ctx = {'date': orig_date}
6 amount_cur = (ml.credit_currency - ml.debit_currency) * line.percentage / 100
7 amount = self.pool.get('res.currency').compute(cr, uid, ml.currency_id.id, company_currency_id, amount_cur, round=False, context=ctx)
8- # UFTP-169: Use the correction line date in case we are correcting a line that is a correction of another line.
9+
10 date_to_use = orig_date
11+ if ml.journal_id.type == 'hq':
12+ # US-773: keep date when correcting hq entry
13+ date_to_use = False
14+ # UFTP-169: Use the correction line date in case we are correcting a line that is a correction of another line.
15 if ml.corrected_line_id:
16 date_to_use = ml.date
17- self.pool.get('account.analytic.line').write(cr, uid, to_override_ids, {
18- 'account_id': line.analytic_id.id,
19- 'cost_center_id': line.cost_center_id.id,
20- 'destination_id': line.destination_id.id,
21- 'amount_currency': amount_cur,
22- 'amount': amount,
23+ vals = {
24+ 'account_id': line.analytic_id.id,
25+ 'cost_center_id': line.cost_center_id.id,
26+ 'destination_id': line.destination_id.id,
27+ 'amount_currency': amount_cur,
28+ 'amount': amount,
29+ }
30+ if date_to_use:
31+ vals.update({
32 'date': date_to_use,
33 'source_date': orig_date,
34 'document_date': orig_document_date,
35 })
36+ self.pool.get('account.analytic.line').write(cr, uid, to_override_ids, vals)
37 # UTP-1118: Fix problem of entry_sequence that is not the right one regarding the journal
38
39 # UFTP-373: The block below is commented out, as there is no reason to replace the Seq in here
40
41=== modified file 'analytic_distribution/analytic_line.py'
42--- analytic_distribution/analytic_line.py 2015-11-20 10:11:55 +0000
43+++ analytic_distribution/analytic_line.py 2015-12-04 08:35:31 +0000
44@@ -239,13 +239,26 @@
45 return False
46 if not date:
47 date = strftime('%Y-%m-%d')
48+
49 # Prepare some value
50 account = self.pool.get('account.analytic.account').browse(cr, uid, [account_id], context)[0]
51 context.update({'from': 'mass_reallocation'}) # this permits reallocation to be accepted when rewrite analaytic lines
52- correction_journal_ids = self.pool.get('account.analytic.journal').search(cr, uid, [('type', '=', 'correction'), ('is_current_instance', '=', True)])
53+ move_prefix = self.pool.get('res.users').browse(cr, uid, uid, context).company_id.instance_id.move_prefix
54+
55+ aaj_obj = self.pool.get('account.analytic.journal')
56+ correction_journal_ids = aaj_obj.search(cr, uid, [('type', '=', 'correction'), ('is_current_instance', '=', True)])
57 correction_journal_id = correction_journal_ids and correction_journal_ids[0] or False
58 if not correction_journal_id:
59 raise osv.except_osv(_('Error'), _('No analytic journal found for corrections!'))
60+
61+ # sequence info from GL journal
62+ aj_obj = self.pool.get('account.journal')
63+ gl_correction_journal_ids = aj_obj.search(cr, uid, [('type', '=', 'correction'), ('is_current_instance', '=', True)])
64+ gl_correction_journal_id = gl_correction_journal_ids and gl_correction_journal_ids[0] or False
65+ if not gl_correction_journal_id:
66+ raise osv.except_osv(_('Error'), _('No GL journal found for corrections!'))
67+ gl_correction_journal_rec = aj_obj.browse(cr, uid, gl_correction_journal_id, context=context)
68+
69 # Process lines
70 for aline in self.browse(cr, uid, ids, context=context):
71 if account.category in ['OC', 'DEST']:
72@@ -255,13 +268,31 @@
73 fieldname = 'cost_center_id'
74 if account.category == 'DEST':
75 fieldname = 'destination_id'
76- # if period is not closed, so override line.
77- if period and period.state not in ['done', 'mission-closed']:
78+
79+ # update or reverse ?
80+ update = period and period.state not in ['done', 'mission-closed']
81+ if aline.journal_id.type == 'hq':
82+ # US-773/2: if HQ entry always like period closed fashion
83+ update = False
84+
85+ if update:
86+ # not mission close: override line
87 # Update account # Date: UTP-943 speak about original date for non closed periods
88- self.write(cr, uid, [aline.id], {fieldname: account_id, 'date': aline.date,
89- 'source_date': aline.source_date or aline.date}, context=context)
90+ vals = {
91+ fieldname: account_id,
92+ 'date': aline.date,
93+ 'source_date': aline.source_date or aline.date,
94+ }
95+ self.write(cr, uid, [aline.id], vals, context=context)
96 # else reverse line before recreating them with right values
97 else:
98+ # mission close or + or HQ entry: reverse
99+
100+ # compute entry sequence
101+ seq_num_ctx = period and {'fiscalyear_id': period.fiscalyear_id.id} or None
102+ seqnum = self.pool.get('ir.sequence').get_id(cr, uid, gl_correction_journal_rec.sequence_id.id, context=seq_num_ctx)
103+ entry_seq = "%s-%s-%s" % (move_prefix, gl_correction_journal_rec.code, seqnum)
104+
105 # First reverse line
106 rev_ids = self.pool.get('account.analytic.line').reverse(cr, uid, [aline.id], posting_date=date)
107 # UTP-943: Shoud have a correction journal on these lines
108@@ -279,6 +310,13 @@
109 self.pool.get('account.analytic.line').write(cr, uid, cor_ids, {'last_corrected_id': aline.id})
110 # finally flag analytic line as reallocated
111 self.pool.get('account.analytic.line').write(cr, uid, [aline.id], {'is_reallocated': True})
112+
113+ if isinstance(rev_ids, (int, long, )):
114+ rev_ids = [rev_ids]
115+ if isinstance(cor_ids, (int, long, )):
116+ cor_ids = [cor_ids]
117+ for rev_cor_id in rev_ids + cor_ids:
118+ cr.execute('update account_analytic_line set entry_sequence = %s where id = %s', (entry_seq, rev_cor_id))
119 else:
120 # Update account
121 self.write(cr, uid, [aline.id], {'account_id': account_id}, context=context)

Subscribers

People subscribed via source and target branches