Merge lp:~odossmann/unifield-wm/UTP_1011 into lp:unifield-wm

Proposed by Olivier DOSSMANN
Status: Needs review
Proposed branch: lp:~odossmann/unifield-wm/UTP_1011
Merge into: lp:unifield-wm
Diff against target: 237 lines (+143/-5)
5 files modified
account_corrections/account_move_line.py (+47/-1)
account_override/account_move_line.py (+75/-2)
analytic_distribution/analytic_distribution_wizard_view.xml (+6/-0)
analytic_distribution/wizard/analytic_distribution_wizard.py (+13/-0)
analytic_distribution/wizard/mass_reallocation_wizard.py (+2/-2)
To merge this branch: bzr merge lp:~odossmann/unifield-wm/UTP_1011
Reviewer Review Type Date Requested Status
UniField Reviewer Team Pending
Review via email: mp+235103@code.launchpad.net

Description of the change

For seeing changes.

To post a comment you must log in.
lp:~odossmann/unifield-wm/UTP_1011 updated
2215. By Olivier DOSSMANN

UTP-1011 [FIX] Correction from Coordo: Now we check our current instance to see if used cost center are in target CC. If not, do not make the line.

2216. By Olivier DOSSMANN

UTP-1011 [IMP] Display a message on journal item allocation to explain that this analytic distribution was reallocated upstream.

2217. By Olivier DOSSMANN

UTP-1011 [FIX] Analytic correction on multiple lines from project to coordo: Fix the fact that we don't delete right lines.

Unmerged revisions

2217. By Olivier DOSSMANN

UTP-1011 [FIX] Analytic correction on multiple lines from project to coordo: Fix the fact that we don't delete right lines.

2216. By Olivier DOSSMANN

UTP-1011 [IMP] Display a message on journal item allocation to explain that this analytic distribution was reallocated upstream.

2215. By Olivier DOSSMANN

UTP-1011 [FIX] Correction from Coordo: Now we check our current instance to see if used cost center are in target CC. If not, do not make the line.

2214. By Olivier DOSSMANN

UTP-1011 [FIX] Correction through synchronization: Fetch correctly the distribution from the coordo level to project one

2213. By Olivier DOSSMANN

UTP-1011 [FIX] Generate a correct dictionnary with SD REF values of element so that we can find them at project level

2212. By Olivier DOSSMANN

UTP-1011 [WIP] work in progress - Attempt to send and receive analytic distribution

2211. By Olivier DOSSMANN

UTP-1011 [WIP] work in progress - Change corrected_upstream field to a binary one to include analytic distribution into the move line

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'account_corrections/account_move_line.py'
2--- account_corrections/account_move_line.py 2014-05-12 12:55:30 +0000
3+++ account_corrections/account_move_line.py 2014-09-25 13:09:07 +0000
4@@ -887,7 +887,53 @@
5 # UF-1746: Set also all other move lines as corrected upstream to disallow projet user to correct any move line of this move.
6 move_ids = [x and x.get('move_id', False) and x.get('move_id')[0] for x in self.read(cr, uid, ids, ['move_id'], context=context)]
7 ml_ids = self.search(cr, uid, [('move_id', 'in', move_ids)])
8- self.write(cr, uid, ml_ids, {'corrected_upstream': True}, check=False, update_check=False, context=context)
9+ # UTP-1011: Make a dictionnary of the all entire analytic distribution and load it into corrected_upstream with cPickle (serialization)
10+ from cPickle import dumps
11+ distrib_obj = self.pool.get('analytic.distribution')
12+ for ml in self.read(cr, uid, ml_ids, ['analytic_distribution_id'], context=context):
13+ distrib_id = ml.get('analytic_distribution_id', False)
14+ ml_id = ml.get('id')
15+ if not distrib_id:
16+ continue
17+ else:
18+ distrib_id = distrib_id[0]
19+ ml_result = {
20+ 'distrib_id': ml.get('analytic_distribution_id', False),
21+ 'funding_pool_lines': [],
22+ 'cost_center_lines': [],
23+ 'free_1_lines': [],
24+ 'free_2_lines': [],
25+ 'corrected': False,
26+ }
27+ # Give another information: if this line was initially corrected or not. If this line was not originally corrected, so do no specific changes on it. Just keep the corrected_upstream field as it is.
28+ if ml_id in ids:
29+ ml_result.update({'corrected': True})
30+ # Browse distribution to remember it
31+ distrib = distrib_obj.browse(cr, uid, [distrib_id], context=context)[0]
32+ for object_name in [('funding_pool_lines', 'funding.pool.distribution.line'), ('cost_center_lines', 'cost.center.distribution.line'), ('free_1_lines', 'free.1.distribution.line'), ('free_2_lines', 'free.2.distribution.line')]:
33+ distrib_lines = getattr(distrib, object_name[0], False)
34+ if distrib_lines:
35+ # fetch info from the object
36+ object_obj = self.pool.get(object_name[1])
37+ fields = ['date', 'source_date', 'percentage', 'destination_id/id', 'analytic_id/id', 'currency_id/id']
38+ if object_name[0] == 'funding_pool_lines':
39+ fields.append('cost_center_id/id')
40+ distrib_line_ids = [x.id for x in distrib_lines]
41+ distrib_list = []
42+ if isinstance(distrib_line_ids, (int, long)):
43+ distrib_line_ids = [distrib_line_ids]
44+ for distrib_line_id in distrib_line_ids:
45+ distrib_dict = {}
46+ for field in fields:
47+ distrib_dict.update({
48+ field: object_obj.export_data(cr, uid, [distrib_line_id], [field], context=context).get('datas', [False])[0],
49+ })
50+ distrib_list.append(distrib_dict)
51+ ml_result[object_name[0]].append(distrib_dict)
52+ # Transform dict into a serialized object
53+ binary_content = False
54+ binary_content = dumps(ml_result)
55+ self.write(cr, uid, ml_id, {'corrected_upstream': binary_content}, check=False, update_check=False, context=context)
56 return True
57
58 account_move_line()
59
60=== modified file 'account_override/account_move_line.py'
61--- account_override/account_move_line.py 2014-09-09 08:14:21 +0000
62+++ account_override/account_move_line.py 2014-09-25 13:09:07 +0000
63@@ -260,7 +260,7 @@
64 ),
65 'is_reconciled': fields.function(_get_is_reconciled, fnct_search=_search_is_reconciled, type='boolean', method=True, string="Is reconciled", help="Is that line partially/totally reconciled?"),
66 'balance_currency': fields.function(_balance_currency, fnct_search=_balance_currency_search, method=True, string='Balance Booking'),
67- 'corrected_upstream': fields.boolean('Corrected from CC/HQ', readonly=True, help='This line have been corrected from Coordo or HQ level to a cost center that have the same level or superior.'),
68+ 'corrected_upstream': fields.text('Corrected from CC/HQ', readonly=True, help='This line have been corrected from Coordo or HQ level to a cost center that have the same level or superior. The binary contains the analytic distribution found at Coordo Level.'),
69 'line_number': fields.integer(string='Line Number'),
70 'invoice_partner_link': fields.many2one('account.invoice', string="Invoice partner link", readonly=True,
71 help="This link implies this line come from the total of an invoice, directly from partner account.", ondelete="cascade"),
72@@ -347,6 +347,65 @@
73 raise osv.except_osv(_('Warning'), _('Given date [%s] is outside defined period: %s') % (date, period and period.name or ''))
74 return True
75
76+ def _generate_distribution_from_corrected(self, cr, uid, corrected_dict, context=None):
77+ """
78+ Check given dictionary, extract distribution and make a new distribution in the system.
79+ Then return result
80+ """
81+ res = False
82+ if context is None:
83+ context = {}
84+ # If not "corrected" or "corrected" is False, then return False
85+ if not corrected_dict or not corrected_dict.get('corrected', False):
86+ return res
87+ # Example of what is fetch
88+ # {'corrected': True, 'free_2_lines': [], 'distrib_id': (1, u'0 CC; 1 FP; 0 F1; 0 F2'), 'cost_center_lines': [], 'funding_pool_lines': [{'destination_id/id': [u'sd.analytic_distribution_analytic_account_destination_operation'], 'cost_center_id/id': [u'sd.OC_HT101_HT101'], 'analytic_id/id': [u'sd.analytic_distribution_analytic_account_msf_private_funds'], 'source_date': [u'2014-09-16'], 'date': [u'2014-09-16'], 'percentage': [u'100.0']}], 'free_1_lines': []}
89+ distrib_id = self.pool.get('analytic.distribution').create(cr, uid, {}, context=context)
90+ objs = [('funding_pool_lines', 'funding.pool.distribution.line'), ('cost_center_lines', 'cost.center.distribution.line'), ('free_2_lines', 'free.2.distribution.line'), ('free_1_lines', 'free.1.distribution.line')]
91+ data_obj = self.pool.get('ir.model.data')
92+ for obj in objs:
93+ if corrected_dict.get(obj[0], False):
94+ for line in corrected_dict.get(obj[0]):
95+ # Check for FP lines that CC is allowed
96+ if obj[0] == 'funding_pool_lines' and line.get('cost_center_id/id'):
97+ # Search ID for the cost center
98+ module, xml_id = line.get('cost_center_id/id')[0].rsplit('.', 1)
99+ data_ids = data_obj.search(cr, uid, [('model', '=', 'account.analytic.account'), ('name', '=', xml_id), ('module', '=', module)])
100+ if data_ids and len(data_ids) == 1:
101+ data = data_obj.read(cr, uid, data_ids, ['res_id'])[0]
102+ cc_id = data.get('res_id')
103+ # Pass the line creation if CC is not in targeted CC
104+ target_cc = self.pool.get('res.users').browse(cr, uid, uid).company_id.instance_id.target_cost_center_ids
105+ target_ids = [x.id for x in target_cc if x]
106+ if cc_id not in target_ids:
107+ continue
108+ # Initial values (distribution that we will use)
109+ vals = {
110+ 'distribution_id': distrib_id,
111+ }
112+ # Normal fields
113+ for field in ['source_date', 'date', 'percentage']:
114+ vals.update({
115+ field: line[field] and line[field][0] or False,
116+ })
117+ # Specific fields
118+ fields = [('analytic_id/id', 'analytic_id', 'account.analytic.account'), ('destination_id/id', 'destination_id', 'account.analytic.account'), ('currency_id/id', 'currency_id', 'res.currency')]
119+ if obj[0] == 'funding_pool_lines':
120+ fields.append(('cost_center_id/id', 'cost_center_id', 'account.analytic.account'))
121+ for field in fields:
122+ if line.get(field[0]):
123+ module, xml_id = line.get(field[0])[0].rsplit('.', 1)
124+ data_ids = data_obj.search(cr, uid, [('model', '=', field[2]), ('name', '=', xml_id), ('module', '=', module)])
125+ if data_ids and len(data_ids) == 1:
126+ data = data_obj.read(cr, uid, data_ids, ['res_id'])[0]
127+ vals.update({
128+ field[1]: data.get('res_id'),
129+ })
130+ self.pool.get(obj[1]).create(cr, uid, vals)
131+ if distrib_id:
132+ res = distrib_id
133+ return res
134+
135 def create(self, cr, uid, vals, context=None, check=True):
136 """
137 Filled in 'document_date' if we come from tests
138@@ -383,7 +442,8 @@
139
140 def write(self, cr, uid, ids, vals, context=None, check=True, update_check=True):
141 """
142- Check document_date and date validity
143+ Check document_date and date validity.
144+ If vals contains corrected_upstream (during synchronization), adapt the analytic distribution to the new one.
145 """
146 if not context:
147 context = {}
148@@ -403,6 +463,19 @@
149 context.update({'date': m.date})
150 # Note that _check_document_date HAVE TO be BEFORE the super write. If not, some problems appears in ournal entries document/posting date changes at the same time!
151 self._check_document_date(cr, uid, ids, vals)
152+ # UTP-1011: If corrected_upstream, apply the given analytic distribution. But only when you come from synchro and that you are in project level
153+ if vals.get('corrected_upstream', False) and context.get('sync_update_execution', False):
154+ company = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id
155+ if company and company.instance_id and company.instance_id.level in ['project']:
156+ from cPickle import loads
157+ corrected_dict = loads(vals.get('corrected_upstream').encode('utf-8'))
158+ if corrected_dict:
159+ distrib_id = self._generate_distribution_from_corrected(cr, uid, corrected_dict, context=context)
160+ if distrib_id:
161+ vals.update({'analytic_distribution_id': distrib_id})
162+ # Change check and update_check so that it deletes all analytic lines and recreate them with the right analytic distribution
163+ check = True
164+ update_check = True
165 res = super(account_move_line, self).write(cr, uid, ids, vals, context=context, check=check, update_check=update_check)
166 return res
167
168
169=== modified file 'analytic_distribution/analytic_distribution_wizard_view.xml'
170--- analytic_distribution/analytic_distribution_wizard_view.xml 2014-01-15 13:48:41 +0000
171+++ analytic_distribution/analytic_distribution_wizard_view.xml 2014-09-25 13:09:07 +0000
172@@ -93,6 +93,12 @@
173 <label string="*: this action will copy the analytic distribution from the header to the line allowing then the user to make changes starting from the copied distribution." colspan="3" />
174 </group>
175 </group>
176+ <group colspan="4">
177+ <field name="corrected_upstream" invisible="1"/>
178+ <group colspan="3" col="3" attrs="{'invisible': [('corrected_upstream', '=', False)]}">
179+ <label string="This allocation was corrected upstream."/>
180+ </group>
181+ </group>
182 <group colspan="4" col="2" attrs="{'invisible': [('state', '!=', 'cc')]}">
183 <separator string="Cost Center"/>
184 <field colspan="4" name="line_ids" nolabel="1" widget="one2many_list" context="{'mode': entry_mode, 'from_purchase': purchase_id, 'from_sale_order': sale_order_id, 'parent_id':active_id}" attrs="{'readonly': [('is_writable', '=', False)]}"/>
185
186=== modified file 'analytic_distribution/wizard/analytic_distribution_wizard.py'
187--- analytic_distribution/wizard/analytic_distribution_wizard.py 2014-09-19 13:19:14 +0000
188+++ analytic_distribution/wizard/analytic_distribution_wizard.py 2014-09-25 13:09:07 +0000
189@@ -555,6 +555,18 @@
190 res[wiz.id] = abs(wiz.total_amount)
191 return res
192
193+ def _get_corrected_upstream(self, cr, uid, ids, name, args, context=None):
194+ """
195+ Check if Journal Item have a corrected_upstream field filled in. If yes, corrected_upstream on wizard is True.
196+ """
197+ # Prepare some values
198+ res = {}
199+ for wiz in self.browse(cr, uid, ids):
200+ res[wiz.id] = False
201+ if wiz.move_line_id and wiz.move_line_id.corrected_upstream:
202+ res[wiz.id] = True
203+ return res
204+
205 def _get_register_line_state(self, cr, uid, ids, name, args, context=None):
206 """
207 Get register line state if present.
208@@ -606,6 +618,7 @@
209 'partner_type': fields.text(string='Partner Type of FO/PO', required=False, readonly=True), #UF-2138: added the ref to partner type of FO/PO
210 'cash_return_id': fields.many2one('wizard.cash.return', string="Advance Return"),
211 'cash_return_line_id': fields.many2one('wizard.advance.line', string="Advance Return Line"),
212+ 'corrected_upstream': fields.function(_get_corrected_upstream, method=True, string="Corrected upstream?", type='boolean', readonly=True),
213 }
214
215 _defaults = {
216
217=== modified file 'analytic_distribution/wizard/mass_reallocation_wizard.py'
218--- analytic_distribution/wizard/mass_reallocation_wizard.py 2014-06-27 09:29:47 +0000
219+++ analytic_distribution/wizard/mass_reallocation_wizard.py 2014-09-25 13:09:07 +0000
220@@ -193,7 +193,7 @@
221 ('from_write_off', '=', True),
222 ('move_state', '=', 'draft'),
223 ('account_id.category', 'in', ['FREE1', 'FREE2']),
224- ('move_id.corrected_upstream', '=', True)
225+ ('move_id.corrected_upstream', '!=', False)
226 ]
227
228 search_ns_ids = self.pool.get('account.analytic.line').search(cr, uid, search_args, context=context)
229@@ -290,7 +290,7 @@
230 ('from_write_off', '=', True),
231 ('move_state', '=', 'draft'),
232 ('account_id.category', 'in', ['FREE1', 'FREE2']),
233- ('move_id.corrected_upstream', '=', True)
234+ ('move_id.corrected_upstream', '!=', False)
235 ]
236 search_ns_ids = self.pool.get('account.analytic.line').search(cr, uid, search_args)
237 if search_ns_ids:

Subscribers

People subscribed via source and target branches