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

Proposed by jftempo
Status: Merged
Merged at revision: 5372
Proposed branch: lp:~julie-w/unifield-server/US-5616
Merge into: lp:unifield-server
Diff against target: 199 lines (+86/-27)
6 files modified
bin/addons/account_hq_entries/hq_entries.py (+23/-0)
bin/addons/account_hq_entries/wizard/hq_entries_import.py (+3/-0)
bin/addons/analytic_distribution/analytic_distribution.py (+0/-3)
bin/addons/msf_profile/i18n/es_MF.po (+0/-6)
bin/addons/msf_profile/i18n/fr_MF.po (+18/-6)
bin/addons/sync_so/specific_xml_id.py (+42/-12)
To merge this branch: bzr merge lp:~julie-w/unifield-server/US-5616
Reviewer Review Type Date Requested Status
UniField Reviewer Team Pending
Review via email: mp+364810@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_hq_entries/hq_entries.py'
2--- bin/addons/account_hq_entries/hq_entries.py 2019-01-09 10:36:58 +0000
3+++ bin/addons/account_hq_entries/hq_entries.py 2019-03-27 16:03:16 +0000
4@@ -496,9 +496,31 @@
5 # If destination given, search if given
6 return res
7
8+ def _check_cc(self, cr, uid, ids, context=None):
9+ """
10+ At synchro time sets HQ entry to Not Run if the Cost Center used in the line doesn't exist or is inactive
11+ """
12+ if isinstance(ids, (int, long)):
13+ ids = [ids]
14+ if context is None:
15+ context = {}
16+ if context.get('sync_update_execution'):
17+ for hq_entry in self.browse(cr, uid, ids, fields_to_fetch=['cost_center_id', 'date', 'name'], context=context):
18+ if not hq_entry.cost_center_id:
19+ raise osv.except_osv(_('Warning'), _('The Cost Center of the HQ entry "%s" doesn\'t exist in the system.') % hq_entry.name)
20+ elif hq_entry.date: # posting date
21+ hq_date = hq_entry.date
22+ cc_date_start = hq_entry.cost_center_id.date_start
23+ cc_date_end = hq_entry.cost_center_id.date or False
24+ if (hq_date < cc_date_start) or (cc_date_end and hq_date >= cc_date_end):
25+ raise osv.except_osv(_('Warning'), _('The Cost Center %s used in the HQ entry "%s" is inactive.') %
26+ (hq_entry.cost_center_id.code or '', hq_entry.name))
27+ return True
28+
29 def create(self, cr, uid, vals, context=None):
30 new_id = super(hq_entries, self).create(cr, uid, vals, context)
31 self._check_active_account(cr, uid, [new_id], context=context)
32+ self._check_cc(cr, uid, [new_id], context=context)
33 return new_id
34
35 def write(self, cr, uid, ids, vals, context=None):
36@@ -531,6 +553,7 @@
37 self.check_ad_change_allowed(cr, uid, ids, vals, context=context)
38 res = super(hq_entries, self).write(cr, uid, ids, vals, context)
39 self._check_active_account(cr, uid, ids, context=context)
40+ self._check_cc(cr, uid, ids, context=context)
41 return res
42
43 def unlink(self, cr, uid, ids, context=None):
44
45=== modified file 'bin/addons/account_hq_entries/wizard/hq_entries_import.py'
46--- bin/addons/account_hq_entries/wizard/hq_entries_import.py 2019-02-06 09:25:31 +0000
47+++ bin/addons/account_hq_entries/wizard/hq_entries_import.py 2019-03-27 16:03:16 +0000
48@@ -178,6 +178,9 @@
49 raise osv.except_osv(_('Error'), _('Cost Center "%s" doesn\'t exist!') % (cost_center,))
50 cc_id = cc_id[0]
51 if cc_id:
52+ # check that the CC or its parent is targeted to an instance
53+ if not hq_obj.get_target_id(cr, uid, cc_id, context=context):
54+ raise osv.except_osv(_('Error'), _('The Cost Center "%s" (or its parent) must be "targeted" to a Proprietary Instance.') % (cost_center,))
55 aa_check_ids.append(cc_id)
56
57 vals.update({'destination_id_first_value': destination_id, 'destination_id': destination_id, 'cost_center_id': cc_id, 'analytic_id': fp_id, 'cost_center_id_first_value': cc_id, 'analytic_id_first_value': fp_id, 'free_1_id': free1_id, 'free_2_id': free2_id,})
58
59=== modified file 'bin/addons/analytic_distribution/analytic_distribution.py'
60--- bin/addons/analytic_distribution/analytic_distribution.py 2017-02-10 08:51:30 +0000
61+++ bin/addons/analytic_distribution/analytic_distribution.py 2019-03-27 16:03:16 +0000
62@@ -93,9 +93,6 @@
63 if analytic_id == fp_id:
64 is_private_fund = True
65 # DISTRIBUTION VERIFICATION
66- # Check account user_type
67- if account.user_type_code != 'expense':
68- return res, _('Not an expense account')
69 # Check that destination is compatible with account
70 if destination_id not in [x.id for x in account.destination_ids]:
71 return 'invalid', _('Destination not compatible with account')
72
73=== modified file 'bin/addons/msf_profile/i18n/es_MF.po'
74--- bin/addons/msf_profile/i18n/es_MF.po 2018-03-16 11:02:37 +0000
75+++ bin/addons/msf_profile/i18n/es_MF.po 2019-03-27 16:03:16 +0000
76@@ -44707,12 +44707,6 @@
77 msgid "Text Error"
78 msgstr "Error de texto"
79
80-#. module: analytic_distribution
81-#: code:addons/analytic_distribution/analytic_distribution.py:448
82-#, python-format
83-msgid "Not an expense account"
84-msgstr "Not an expense account"
85-
86 #. module: service_purchasing
87 #: code:addons/service_purchasing/service_purchasing.py:244
88 #, python-format
89
90=== modified file 'bin/addons/msf_profile/i18n/fr_MF.po'
91--- bin/addons/msf_profile/i18n/fr_MF.po 2019-03-04 11:05:48 +0000
92+++ bin/addons/msf_profile/i18n/fr_MF.po 2019-03-27 16:03:16 +0000
93@@ -20463,12 +20463,6 @@
94 msgid "Selected Version is for a different product."
95 msgstr "Version Sélectionnée est pour un produit différent."
96
97-#. module: analytic_distribution
98-#: code:addons/analytic_distribution/analytic_distribution.py:98
99-#, python-format
100-msgid "Not an expense account"
101-msgstr "Not an expense account"
102-
103 #. module: account
104 #: model:process.transition,name:account.process_transition_confirmstatementfromdraft0
105 msgid "Confirm statement"
106@@ -105320,6 +105314,24 @@
107 msgid "File line %s: Column \"Item\" must be an integer"
108 msgstr "Fichier ligne %s: La Colonne \"Article\" doit être un entier"
109
110+#. module: account_hq_entries
111+#: code:addons/account_hq_entries/wizard/hq_entries_import.py:183
112+#, python-format
113+msgid "The Cost Center \"%s\" (or its parent) must be \"targeted\" to a Proprietary Instance."
114+msgstr "Le Centre de Coût \"%s\" (ou son parent) doit avoir une Instance Propriétaire \"cible\"."
115+
116+#. module: account_hq_entries
117+#: code:addons/account_hq_entries/hq_entries.py:510
118+#, python-format
119+msgid "The Cost Center of the HQ entry \"%s\" doesn't exist in the system."
120+msgstr "Le Centre de Coût de l'entrée Siège \"%s\" n'existe pas dans le système."
121+
122+#. module: account_hq_entries
123+#: code:addons/account_hq_entries/hq_entries.py:516
124+#, python-format
125+msgid "The Cost Center %s used in the HQ entry \"%s\" is inactive."
126+msgstr "Le Centre de Coût %s utilisé dans l'entrée Siège \"%s\" est inactif."
127+
128 #. module: purchase
129 #: code:addons/purchase/purchase_order_line.py:24
130 #, python-format
131
132=== modified file 'bin/addons/sync_so/specific_xml_id.py'
133--- bin/addons/sync_so/specific_xml_id.py 2018-10-25 12:38:09 +0000
134+++ bin/addons/sync_so/specific_xml_id.py 2019-03-27 16:03:16 +0000
135@@ -146,23 +146,53 @@
136
137 _inherit = 'hq.entries'
138
139+ def get_target_id(self, cr, uid, cost_center_id, context=None):
140+ """
141+ Returns the id of the target CC linked to the cost_center_id, or to its parent if there isn't any.
142+ """
143+ if context is None:
144+ context = {}
145+ target_ids = []
146+ if cost_center_id:
147+ analytic_cc_obj = self.pool.get('account.analytic.account')
148+ target_cc_obj = self.pool.get('account.target.costcenter')
149+ target_ids = target_cc_obj.search(cr, uid,
150+ [('cost_center_id', '=', cost_center_id), ('is_target', '=', True)],
151+ context=context)
152+ if not target_ids:
153+ cc = analytic_cc_obj.browse(cr, uid, cost_center_id, fields_to_fetch=['parent_id'], context=context)
154+ if cc and cc.parent_id:
155+ target_ids = target_cc_obj.search(cr, uid,
156+ [('cost_center_id', '=', cc.parent_id.id), ('is_target', '=', True)],
157+ context=context)
158+ return target_ids and target_ids[0] or False
159+
160 def get_destination_name(self, cr, uid, ids, dest_field, context=None):
161+ """
162+ Gets the instances to which the HQ entries should sync.
163+ For each HQ entry:
164+ 1) Search for the instance:
165+ - to which the CC used in the entry is targeted to
166+ - if there isn't any, to which the PARENT CC is targeted to
167+ 2) The entry will sync to the coordo of the corresponding mission
168+ """
169+ if context is None:
170+ context = {}
171+ target_cc_obj = self.pool.get('account.target.costcenter')
172 if dest_field == 'cost_center_id':
173 res = dict.fromkeys(ids, False)
174 for line_data in self.browse(cr, uid, ids, context=context):
175 if line_data.cost_center_id:
176- cost_center_name = line_data.cost_center_id and \
177- line_data.cost_center_id.code and \
178- line_data.cost_center_id.code[:3] or ""
179- cost_center_ids = self.pool.get('account.analytic.account').search(cr, uid, [('category', '=', 'OC'),
180- ('code', '=', cost_center_name)], context=context)
181- if len(cost_center_ids) > 0:
182- target_ids = self.pool.get('account.target.costcenter').search(cr, uid, [('cost_center_id', '=', cost_center_ids[0]),
183- ('is_target', '=', True)])
184- if len(target_ids) > 0:
185- target = self.pool.get('account.target.costcenter').browse(cr, uid, target_ids[0], context=context)
186- if target.instance_id and target.instance_id.instance:
187- res[line_data.id] = target.instance_id.instance
188+ targeted_instance = False
189+ target_id = self.get_target_id(cr, uid, line_data.cost_center_id.id, context=context)
190+ if target_id:
191+ target = target_cc_obj.browse(cr, uid, target_id, fields_to_fetch=['instance_id'], context=context)
192+ if target.instance_id.level == 'coordo':
193+ targeted_instance = target.instance_id
194+ elif target.instance_id.level == 'project':
195+ targeted_instance = target.instance_id.parent_id or False
196+ if targeted_instance:
197+ res[line_data.id] = targeted_instance.instance
198 return res
199 return super(hq_entries, self).get_destination_name(cr, uid, ids, dest_field, context=context)
200

Subscribers

People subscribed via source and target branches