Merge lp:~julie-w/unifield-server/US-4430 into lp:unifield-server

Proposed by jftempo
Status: Merged
Merged at revision: 4827
Proposed branch: lp:~julie-w/unifield-server/US-4430
Merge into: lp:unifield-server
Diff against target: 178 lines (+157/-0)
2 files modified
bin/addons/msf_profile/data/patches.xml (+5/-0)
bin/addons/msf_profile/msf_profile.py (+152/-0)
To merge this branch: bzr merge lp:~julie-w/unifield-server/US-4430
Reviewer Review Type Date Requested Status
UniField Reviewer Team Pending
Review via email: mp+342266@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/msf_profile/data/patches.xml'
2--- bin/addons/msf_profile/data/patches.xml 2018-03-15 14:46:24 +0000
3+++ bin/addons/msf_profile/data/patches.xml 2018-03-28 07:26:42 +0000
4@@ -1,6 +1,11 @@
5 <?xml version="1.0" encoding="utf-8" ?>
6 <openerp>
7 <data>
8+ <!-- UF8.1 -->
9+ <record id="us_4430_set_puf_to_reversal" model="patch.scripts">
10+ <field name="method">us_4430_set_puf_to_reversal</field>
11+ </record>
12+
13 <!-- UF8.0 -->
14 <record id="set_sequence_main_nomen" model="patch.scripts">
15 <field name="method">set_sequence_main_nomen</field>
16
17=== modified file 'bin/addons/msf_profile/msf_profile.py'
18--- bin/addons/msf_profile/msf_profile.py 2018-03-16 09:40:20 +0000
19+++ bin/addons/msf_profile/msf_profile.py 2018-03-28 07:26:42 +0000
20@@ -51,6 +51,158 @@
21 'model': lambda *a: 'patch.scripts',
22 }
23
24+ # UF8.1
25+ def us_4430_set_puf_to_reversal(self, cr, uid, *a, **b):
26+ """
27+ Context: in case of an SI refund-cancel or modify since US-1255 (UF7.0) the original PUR are marked as reallocated,
28+ since US-4137 (UF7.2) PUF are marked as reversal.
29+ This method fixes the entries generated in between:
30+ - sets the PUF AJIs as is_reversal: will fix the discrepancies in Financing Contracts and Budget Monitoring Report
31+ - sets the PUF JIs as is_si_refund: will make the lines not correctable
32+
33+ Criteria used to spot the JIs to fix:
34+ - JIs booked on a journal having the type "Purchase refund"
35+ - which belong to a JE system
36+ - which are reconciled (implies that all SI headers were booked on a reconcilable account) with a JI:
37+ ==> booked on a journal having the type "Purchase"
38+ ==> which belongs to a JE system
39+ ==> which belongs to a JE having at least one leg set as "corrected"
40+ Cf: - the JI corresponding to the SI header line is not set as corrected during a refund-cancel, only the SI lines are.
41+ - since US-1255 (UF7.0) it is not possible to do a refund-cancel once one of the SI lines has been corrected.
42+ - with a creation date after 7.0
43+ ==> no ending date to cover the diff between UF7.2 patch date at sync server and within each instance
44+ ==> entries generated after 7.2 are already correct and won't be impacted
45+ - which are set neither as "is_si_refund" nor as "reversal".
46+ """
47+ if self.pool.get('sync_client.version'): # exclude sync server + new instances being created
48+ user_obj = self.pool.get('res.users')
49+ update_aji = """
50+ UPDATE account_analytic_line
51+ SET is_reversal = 't'
52+ WHERE move_id IN (
53+ SELECT id FROM account_move_line
54+ WHERE move_id IN (
55+ SELECT DISTINCT(am.id)
56+ FROM account_move_line aml
57+ INNER JOIN account_move am ON aml.move_id = am.id
58+ INNER JOIN account_journal j ON aml.journal_id = j.id
59+ WHERE j.type = 'purchase_refund'
60+ AND am.status = 'sys'
61+ AND aml.create_date > (SELECT applied FROM sync_client_version WHERE name = 'UF7.0' LIMIT 1)
62+ AND aml.is_si_refund = 'f'
63+ AND aml.reversal = 'f'
64+ AND aml.reconcile_id IS NOT NULL
65+ AND aml.reconcile_id IN (
66+ SELECT r.id
67+ FROM account_move_reconcile r
68+ INNER JOIN account_move_line aml ON aml.reconcile_id = r.id
69+ AND aml.id IN (
70+ SELECT aml.id
71+ FROM account_move_line aml
72+ INNER JOIN account_move am ON aml.move_id = am.id
73+ INNER JOIN account_journal j ON aml.journal_id = j.id
74+ WHERE j.type = 'purchase'
75+ AND am.status = 'sys'
76+ AND am.id IN (
77+ SELECT DISTINCT(am.id)
78+ FROM account_move am
79+ INNER JOIN account_move_line aml ON aml.move_id = am.id
80+ WHERE aml.corrected = 't'
81+ )
82+ )
83+ )
84+ )
85+ );
86+ """
87+ update_ji = """
88+ UPDATE account_move_line
89+ SET is_si_refund = 't'
90+ WHERE move_id IN (
91+ SELECT DISTINCT(am.id)
92+ FROM account_move_line aml
93+ INNER JOIN account_move am ON aml.move_id = am.id
94+ INNER JOIN account_journal j ON aml.journal_id = j.id
95+ WHERE j.type = 'purchase_refund'
96+ AND am.status = 'sys'
97+ AND aml.create_date > (SELECT applied FROM sync_client_version WHERE name = 'UF7.0' LIMIT 1)
98+ AND aml.is_si_refund = 'f'
99+ AND aml.reversal = 'f'
100+ AND aml.reconcile_id IS NOT NULL
101+ AND aml.reconcile_id IN (
102+ SELECT r.id
103+ FROM account_move_reconcile r
104+ INNER JOIN account_move_line aml ON aml.reconcile_id = r.id
105+ AND aml.id IN (
106+ SELECT aml.id
107+ FROM account_move_line aml
108+ INNER JOIN account_move am ON aml.move_id = am.id
109+ INNER JOIN account_journal j ON aml.journal_id = j.id
110+ WHERE j.type = 'purchase'
111+ AND am.status = 'sys'
112+ AND am.id IN (
113+ SELECT DISTINCT(am.id)
114+ FROM account_move am
115+ INNER JOIN account_move_line aml ON aml.move_id = am.id
116+ WHERE aml.corrected = 't'
117+ )
118+ )
119+ )
120+ );
121+ """
122+ # trigger the sync for all AJIs whose the prop. instance is the current instance, to cover the use case
123+ # where only AJIs exist in a project because the doc was generated in coordo or in another project
124+ current_instance = user_obj.browse(cr, uid, uid).company_id.instance_id
125+ if current_instance and current_instance.level in ('coordo', 'project'):
126+ trigger_sync = """
127+ UPDATE ir_model_data SET last_modification=NOW(), touched='[''is_reversal'']'
128+ WHERE module='sd' AND model='account.analytic.line' AND res_id IN (
129+ SELECT aal.id
130+ FROM account_analytic_line aal
131+ INNER JOIN account_analytic_journal aaj ON aal.journal_id = aaj.id
132+ WHERE aaj.is_current_instance = 't'
133+ AND move_id IN (
134+ SELECT id FROM account_move_line
135+ WHERE move_id IN (
136+ SELECT DISTINCT(am.id)
137+ FROM account_move_line aml
138+ INNER JOIN account_move am ON aml.move_id = am.id
139+ INNER JOIN account_journal j ON aml.journal_id = j.id
140+ WHERE j.type = 'purchase_refund'
141+ AND am.status = 'sys'
142+ AND aml.create_date > (SELECT applied FROM sync_client_version WHERE name = 'UF7.0' LIMIT 1)
143+ AND aml.is_si_refund = 'f'
144+ AND aml.reversal = 'f'
145+ AND aml.reconcile_id IS NOT NULL
146+ AND aml.reconcile_id IN (
147+ SELECT r.id
148+ FROM account_move_reconcile r
149+ INNER JOIN account_move_line aml ON aml.reconcile_id = r.id
150+ AND aml.id IN (
151+ SELECT aml.id
152+ FROM account_move_line aml
153+ INNER JOIN account_move am ON aml.move_id = am.id
154+ INNER JOIN account_journal j ON aml.journal_id = j.id
155+ WHERE j.type = 'purchase'
156+ AND am.status = 'sys'
157+ AND am.id IN (
158+ SELECT DISTINCT(am.id)
159+ FROM account_move am
160+ INNER JOIN account_move_line aml ON aml.move_id = am.id
161+ WHERE aml.corrected = 't'
162+ )
163+ )
164+ )
165+ )
166+ )
167+ );
168+ """
169+ cr.execute(trigger_sync)
170+ self._logger.warn('%s entries for which a sync will be triggered.' % (cr.rowcount,))
171+ cr.execute(update_aji)
172+ self._logger.warn('%s AJI updated.' % (cr.rowcount,))
173+ cr.execute(update_ji)
174+ self._logger.warn('%s JI updated.' % (cr.rowcount,))
175+
176 # UF8.0
177 def set_sequence_main_nomen(self, cr, uid, *a, **b):
178 nom = ['MED', 'LOG', 'LIB', 'SRV']

Subscribers

People subscribed via source and target branches