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
=== modified file 'bin/addons/msf_homere_interface/wizard/hr_payroll_import.py'
--- bin/addons/msf_homere_interface/wizard/hr_payroll_import.py 2015-11-16 09:24:20 +0000
+++ bin/addons/msf_homere_interface/wizard/hr_payroll_import.py 2016-05-19 07:06:39 +0000
@@ -107,12 +107,42 @@
107 name = ''107 name = ''
108 ref = ''108 ref = ''
109 destination_id = False109 destination_id = False
110 cost_center_id = False
111 # US-671: This flag is used to indicate whether the DEST and CC of employee needs to be updated
112 to_update_employee = False
113 error_message = ""
114
110 if len(data) == 13:115 if len(data) == 13:
111 accounting_code, description, second_description, third, expense, receipt, project, financing_line, \116 accounting_code, description, second_description, third, expense, receipt, project, financing_line, \
112 financing_contract, date, currency, project, analytic_line = zip(data)117 financing_contract, date, currency, project, analytic_line = zip(data)
113 else:118 else:
114 accounting_code, description, second_description, third, expense, receipt, project, financing_line, \119 accounting_code, description, second_description, third, expense, receipt, project, financing_line, \
115 financing_contract, date, currency, axis1, analytic_line, axis2, analytic_line2 = zip(data)120 financing_contract, date, currency, axis1, analytic_line, axis2, analytic_line2 = zip(data)
121
122 # get active cc and dest args before searching
123 aaa_obj = self.pool.get('account.analytic.account')
124 date_args = aaa_obj._search_filter_active(cr, uid, [], None, [('filter_active', '=', True)], context=context)
125
126 #US-671: ONLY APPLY FOR THE SAGA THAT CONTAINS Project and Axis1 columns: Retrieve DEST and CC from the Project and axis1 columns
127 if project and project[0]:
128 # check if the project value exists as a valid costcenter in the local system
129 condition = [('category', '=', 'OC'),('type', '!=', 'view'), ('state', '=', 'open'),('code', '=ilike', project[0]),]
130 condition.extend(date_args)
131 cc_ids = aaa_obj.search(cr, uid, condition, context=context)
132 if cc_ids and cc_ids[0]:
133 cost_center_id = cc_ids[0]
134 else:
135 error_message = "Invalid Cost Center [" + project[0] + "] will be ignored. "
136 if axis1 and axis1[0]:
137 # check if the value exists as a valid DEST in the local system
138 condition = [('category', '=', 'DEST'),('type', '!=', 'view'),('code', '=ilike', axis1[0]),]
139 date_args.extend(condition)
140 dest_ids = aaa_obj.search(cr, uid, date_args, context=context)
141 if dest_ids and dest_ids[0]:
142 destination_id = dest_ids[0]
143 else:
144 error_message = error_message + "Invalid Destination [" + axis1[0] + "] will be ignored."
145
116 # Check period146 # Check period
117 if not date and not date[0]:147 if not date and not date[0]:
118 raise osv.except_osv(_('Warning'), _('A date is missing!'))148 raise osv.except_osv(_('Warning'), _('A date is missing!'))
@@ -140,6 +170,7 @@
140 raise osv.except_osv(_('Warning'), _('The accounting code \'%s\' doesn\'t exist!') % (ustr(accounting_code[0]),))170 raise osv.except_osv(_('Warning'), _('The accounting code \'%s\' doesn\'t exist!') % (ustr(accounting_code[0]),))
141 if len(account_ids) > 1:171 if len(account_ids) > 1:
142 raise osv.except_osv(_('Warning'), _('There is more than one account that have \'%s\' code!') % (ustr(accounting_code[0]),))172 raise osv.except_osv(_('Warning'), _('There is more than one account that have \'%s\' code!') % (ustr(accounting_code[0]),))
173
143 # Fetch DEBIT/CREDIT174 # Fetch DEBIT/CREDIT
144 debit = 0.0175 debit = 0.0
145 credit = 0.0176 credit = 0.0
@@ -199,7 +230,10 @@
199 # US_263: get employee destination, if haven't get default destination230 # US_263: get employee destination, if haven't get default destination
200 if employee_id:231 if employee_id:
201 emp = self.pool.get('hr.employee').browse(cr, uid, employee_id, context=context)232 emp = self.pool.get('hr.employee').browse(cr, uid, employee_id, context=context)
202 if emp.destination_id:233 if destination_id and destination_id != emp.destination_id.id:
234 to_update_employee = True # turn the flag to update the employee
235
236 if not destination_id and emp.destination_id: # US-671: Only update if the destination from the import is not valid
203 destination_id = emp.destination_id.id237 destination_id = emp.destination_id.id
204 if not destination_id:238 if not destination_id:
205 if not account.default_destination_id:239 if not account.default_destination_id:
@@ -241,21 +275,33 @@
241 # Retrieve analytic distribution from employee275 # Retrieve analytic distribution from employee
242 if employee_id:276 if employee_id:
243 employee_data = self.pool.get('hr.employee').read(cr, uid, employee_id, ['cost_center_id', 'funding_pool_id', 'free1_id', 'free2_id'])277 employee_data = self.pool.get('hr.employee').read(cr, uid, employee_id, ['cost_center_id', 'funding_pool_id', 'free1_id', 'free2_id'])
278 #US-671: use the cost center from the import, if not retrieve from employee
279 temp_cc = employee_data and employee_data.get('cost_center_id', False) and employee_data.get('cost_center_id')[0] or False
280 if cost_center_id and cost_center_id != temp_cc:
281 to_update_employee =True
282 if not cost_center_id:
283 cost_center_id = temp_cc
244 vals.update({284 vals.update({
245 'cost_center_id': employee_data and employee_data.get('cost_center_id', False) and employee_data.get('cost_center_id')[0] or False,285 'cost_center_id': cost_center_id,
246 'funding_pool_id': employee_data and employee_data.get('funding_pool_id', False) and employee_data.get('funding_pool_id')[0] or False,286 'funding_pool_id': employee_data and employee_data.get('funding_pool_id', False) and employee_data.get('funding_pool_id')[0] or False,
247 'free1_id': employee_data and employee_data.get('free1_id', False) and employee_data.get('free1_id')[0] or False,287 'free1_id': employee_data and employee_data.get('free1_id', False) and employee_data.get('free1_id')[0] or False,
248 'free2_id': employee_data and employee_data.get('free2_id', False) and employee_data.get('free2_id')[0] or False,288 'free2_id': employee_data and employee_data.get('free2_id', False) and employee_data.get('free2_id')[0] or False,
249 })289 })
250 # Write payroll entry290 # Write payroll entry
251 if wiz_state != 'simu':291 if wiz_state != 'simu':
292 #US-671: In the process mode, update the employee cost center and destination, and use also this one for the payroll object.
293 ############################ UPDATE THE EMPLOYEE! AND PREPARE THE LOG FILE WITH WARNING!
294 if to_update_employee and employee_id:
295 self.pool.get('hr.employee').write(cr, uid, [employee_id], {'cost_center_id': cost_center_id, 'destination_id': destination_id,}, context)
296
252 res = self.pool.get('hr.payroll.msf').create(cr, uid, vals,297 res = self.pool.get('hr.payroll.msf').create(cr, uid, vals,
253 context={'from': 'import'})298 context={'from': 'import'})
254 if res:299 if res:
255 created += 1300 created += 1
256 else:301 else:
257 created += 1302 created += 1
258 return True, amount, created, vals, currency[0]303 msg = 'Duy Test'
304 return True, amount, created, vals, currency[0], error_message
259305
260 def _get_homere_password(self, cr, uid, pass_type='payroll'):306 def _get_homere_password(self, cr, uid, pass_type='payroll'):
261 ##### UPDATE HOMERE.CONF FILE #####307 ##### UPDATE HOMERE.CONF FILE #####
@@ -477,9 +523,10 @@
477 res = True523 res = True
478 res_amount = 0.0524 res_amount = 0.0
479 amount = 0.0525 amount = 0.0
526 error_msg = ""
480 for line in reader:527 for line in reader:
481 processed += 1528 processed += 1
482 update, amount, nb_created, vals, ccy = self.update_payroll_entries(529 update, amount, nb_created, vals, ccy, msg = self.update_payroll_entries(
483 cr, uid, data=line, field=field,530 cr, uid, data=line, field=field,
484 date_format=wiz.date_format,531 date_format=wiz.date_format,
485 wiz_state=wiz.state)532 wiz_state=wiz.state)
@@ -490,6 +537,10 @@
490 header_vals = vals537 header_vals = vals
491 header_vals['currency_code'] = ccy538 header_vals['currency_code'] = ccy
492 created += nb_created539 created += nb_created
540
541 if msg:
542 error_msg += "Line " + str(processed) + ": " + msg + " \n"
543
493 # Check balance544 # Check balance
494 res_amount_rounded = round(res_amount, 2)545 res_amount_rounded = round(res_amount, 2)
495 if res_amount_rounded != 0.0:546 if res_amount_rounded != 0.0:
@@ -536,7 +587,13 @@
536587
537 if wiz_state == 'simu' and ids:588 if wiz_state == 'simu' and ids:
538 # US_201: if check raise no error, change state to process589 # US_201: if check raise no error, change state to process
539 self.write(cr, uid, [wiz.id], {'state': 'proceed'})590 # US-671: Show message in the wizard if there was warning or not.
591 if error_msg:
592 error_msg = "Import can be processed but with the following warnings:\n-------------------- \n" + error_msg
593 else:
594 error_msg = "No warning found for this file. Import can be now processed."
595
596 self.write(cr, uid, [wiz.id], {'state': 'proceed', 'msg': error_msg})
540 view_id = self.pool.get('ir.model.data').get_object_reference(cr,597 view_id = self.pool.get('ir.model.data').get_object_reference(cr,
541 uid, 'msf_homere_interface', 'payroll_import_wizard')598 uid, 'msf_homere_interface', 'payroll_import_wizard')
542 view_id = view_id and view_id[1] or False599 view_id = view_id and view_id[1] or False
@@ -563,7 +620,7 @@
563 # This is to redirect to Payroll Tree View620 # This is to redirect to Payroll Tree View
564 context.update({'from': 'payroll_import'})621 context.update({'from': 'payroll_import'})
565622
566 res_id = self.pool.get('hr.payroll.import.confirmation').create(cr, uid, {'filename': filename,'created': created, 'total': processed, 'state': 'payroll'}, context=context)623 res_id = self.pool.get('hr.payroll.import.confirmation').create(cr, uid, {'filename': filename,'created': created, 'total': processed, 'state': 'payroll',}, context=context)
567624
568 return {625 return {
569 'name': 'Payroll Import Confirmation',626 'name': 'Payroll Import Confirmation',

Subscribers

People subscribed via source and target branches

to all changes: