Merge lp:~unifield-team/unifield-server/us-671-homere-import into lp:unifield-server

Proposed by jftempo
Status: Merged
Merged at revision: 3754
Proposed branch: lp:~unifield-team/unifield-server/us-671-homere-import
Merge into: lp:unifield-server
Diff against target: 149 lines (+63/-6)
1 file modified
bin/addons/msf_homere_interface/wizard/hr_payroll_import.py (+63/-6)
To merge this branch: bzr merge lp:~unifield-team/unifield-server/us-671-homere-import
Reviewer Review Type Date Requested Status
UniField Reviewer Team Pending
Review via email: mp+295156@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_homere_interface/wizard/hr_payroll_import.py'
2--- bin/addons/msf_homere_interface/wizard/hr_payroll_import.py 2015-11-16 09:24:20 +0000
3+++ bin/addons/msf_homere_interface/wizard/hr_payroll_import.py 2016-05-19 07:06:39 +0000
4@@ -107,12 +107,42 @@
5 name = ''
6 ref = ''
7 destination_id = False
8+ cost_center_id = False
9+ # US-671: This flag is used to indicate whether the DEST and CC of employee needs to be updated
10+ to_update_employee = False
11+ error_message = ""
12+
13 if len(data) == 13:
14 accounting_code, description, second_description, third, expense, receipt, project, financing_line, \
15 financing_contract, date, currency, project, analytic_line = zip(data)
16 else:
17 accounting_code, description, second_description, third, expense, receipt, project, financing_line, \
18 financing_contract, date, currency, axis1, analytic_line, axis2, analytic_line2 = zip(data)
19+
20+ # get active cc and dest args before searching
21+ aaa_obj = self.pool.get('account.analytic.account')
22+ date_args = aaa_obj._search_filter_active(cr, uid, [], None, [('filter_active', '=', True)], context=context)
23+
24+ #US-671: ONLY APPLY FOR THE SAGA THAT CONTAINS Project and Axis1 columns: Retrieve DEST and CC from the Project and axis1 columns
25+ if project and project[0]:
26+ # check if the project value exists as a valid costcenter in the local system
27+ condition = [('category', '=', 'OC'),('type', '!=', 'view'), ('state', '=', 'open'),('code', '=ilike', project[0]),]
28+ condition.extend(date_args)
29+ cc_ids = aaa_obj.search(cr, uid, condition, context=context)
30+ if cc_ids and cc_ids[0]:
31+ cost_center_id = cc_ids[0]
32+ else:
33+ error_message = "Invalid Cost Center [" + project[0] + "] will be ignored. "
34+ if axis1 and axis1[0]:
35+ # check if the value exists as a valid DEST in the local system
36+ condition = [('category', '=', 'DEST'),('type', '!=', 'view'),('code', '=ilike', axis1[0]),]
37+ date_args.extend(condition)
38+ dest_ids = aaa_obj.search(cr, uid, date_args, context=context)
39+ if dest_ids and dest_ids[0]:
40+ destination_id = dest_ids[0]
41+ else:
42+ error_message = error_message + "Invalid Destination [" + axis1[0] + "] will be ignored."
43+
44 # Check period
45 if not date and not date[0]:
46 raise osv.except_osv(_('Warning'), _('A date is missing!'))
47@@ -140,6 +170,7 @@
48 raise osv.except_osv(_('Warning'), _('The accounting code \'%s\' doesn\'t exist!') % (ustr(accounting_code[0]),))
49 if len(account_ids) > 1:
50 raise osv.except_osv(_('Warning'), _('There is more than one account that have \'%s\' code!') % (ustr(accounting_code[0]),))
51+
52 # Fetch DEBIT/CREDIT
53 debit = 0.0
54 credit = 0.0
55@@ -199,7 +230,10 @@
56 # US_263: get employee destination, if haven't get default destination
57 if employee_id:
58 emp = self.pool.get('hr.employee').browse(cr, uid, employee_id, context=context)
59- if emp.destination_id:
60+ if destination_id and destination_id != emp.destination_id.id:
61+ to_update_employee = True # turn the flag to update the employee
62+
63+ if not destination_id and emp.destination_id: # US-671: Only update if the destination from the import is not valid
64 destination_id = emp.destination_id.id
65 if not destination_id:
66 if not account.default_destination_id:
67@@ -241,21 +275,33 @@
68 # Retrieve analytic distribution from employee
69 if employee_id:
70 employee_data = self.pool.get('hr.employee').read(cr, uid, employee_id, ['cost_center_id', 'funding_pool_id', 'free1_id', 'free2_id'])
71+ #US-671: use the cost center from the import, if not retrieve from employee
72+ temp_cc = employee_data and employee_data.get('cost_center_id', False) and employee_data.get('cost_center_id')[0] or False
73+ if cost_center_id and cost_center_id != temp_cc:
74+ to_update_employee =True
75+ if not cost_center_id:
76+ cost_center_id = temp_cc
77 vals.update({
78- 'cost_center_id': employee_data and employee_data.get('cost_center_id', False) and employee_data.get('cost_center_id')[0] or False,
79+ 'cost_center_id': cost_center_id,
80 'funding_pool_id': employee_data and employee_data.get('funding_pool_id', False) and employee_data.get('funding_pool_id')[0] or False,
81 'free1_id': employee_data and employee_data.get('free1_id', False) and employee_data.get('free1_id')[0] or False,
82 'free2_id': employee_data and employee_data.get('free2_id', False) and employee_data.get('free2_id')[0] or False,
83 })
84 # Write payroll entry
85 if wiz_state != 'simu':
86+ #US-671: In the process mode, update the employee cost center and destination, and use also this one for the payroll object.
87+ ############################ UPDATE THE EMPLOYEE! AND PREPARE THE LOG FILE WITH WARNING!
88+ if to_update_employee and employee_id:
89+ self.pool.get('hr.employee').write(cr, uid, [employee_id], {'cost_center_id': cost_center_id, 'destination_id': destination_id,}, context)
90+
91 res = self.pool.get('hr.payroll.msf').create(cr, uid, vals,
92 context={'from': 'import'})
93 if res:
94 created += 1
95 else:
96 created += 1
97- return True, amount, created, vals, currency[0]
98+ msg = 'Duy Test'
99+ return True, amount, created, vals, currency[0], error_message
100
101 def _get_homere_password(self, cr, uid, pass_type='payroll'):
102 ##### UPDATE HOMERE.CONF FILE #####
103@@ -477,9 +523,10 @@
104 res = True
105 res_amount = 0.0
106 amount = 0.0
107+ error_msg = ""
108 for line in reader:
109 processed += 1
110- update, amount, nb_created, vals, ccy = self.update_payroll_entries(
111+ update, amount, nb_created, vals, ccy, msg = self.update_payroll_entries(
112 cr, uid, data=line, field=field,
113 date_format=wiz.date_format,
114 wiz_state=wiz.state)
115@@ -490,6 +537,10 @@
116 header_vals = vals
117 header_vals['currency_code'] = ccy
118 created += nb_created
119+
120+ if msg:
121+ error_msg += "Line " + str(processed) + ": " + msg + " \n"
122+
123 # Check balance
124 res_amount_rounded = round(res_amount, 2)
125 if res_amount_rounded != 0.0:
126@@ -536,7 +587,13 @@
127
128 if wiz_state == 'simu' and ids:
129 # US_201: if check raise no error, change state to process
130- self.write(cr, uid, [wiz.id], {'state': 'proceed'})
131+ # US-671: Show message in the wizard if there was warning or not.
132+ if error_msg:
133+ error_msg = "Import can be processed but with the following warnings:\n-------------------- \n" + error_msg
134+ else:
135+ error_msg = "No warning found for this file. Import can be now processed."
136+
137+ self.write(cr, uid, [wiz.id], {'state': 'proceed', 'msg': error_msg})
138 view_id = self.pool.get('ir.model.data').get_object_reference(cr,
139 uid, 'msf_homere_interface', 'payroll_import_wizard')
140 view_id = view_id and view_id[1] or False
141@@ -563,7 +620,7 @@
142 # This is to redirect to Payroll Tree View
143 context.update({'from': 'payroll_import'})
144
145- res_id = self.pool.get('hr.payroll.import.confirmation').create(cr, uid, {'filename': filename,'created': created, 'total': processed, 'state': 'payroll'}, context=context)
146+ res_id = self.pool.get('hr.payroll.import.confirmation').create(cr, uid, {'filename': filename,'created': created, 'total': processed, 'state': 'payroll',}, context=context)
147
148 return {
149 'name': 'Payroll Import Confirmation',

Subscribers

People subscribed via source and target branches

to all changes: