Merge lp:~unifield-team/unifield-server/us-671-homere-import into lp:unifield-server
- us-671-homere-import
- Merge into trunk
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 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
UniField Reviewer Team | Pending | ||
Review via email: mp+295156@code.launchpad.net |
Commit message
Description of the change
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 | 107 | name = '' | 107 | name = '' |
6 | 108 | ref = '' | 108 | ref = '' |
7 | 109 | destination_id = False | 109 | destination_id = False |
8 | 110 | cost_center_id = False | ||
9 | 111 | # US-671: This flag is used to indicate whether the DEST and CC of employee needs to be updated | ||
10 | 112 | to_update_employee = False | ||
11 | 113 | error_message = "" | ||
12 | 114 | |||
13 | 110 | if len(data) == 13: | 115 | if len(data) == 13: |
14 | 111 | accounting_code, description, second_description, third, expense, receipt, project, financing_line, \ | 116 | accounting_code, description, second_description, third, expense, receipt, project, financing_line, \ |
15 | 112 | financing_contract, date, currency, project, analytic_line = zip(data) | 117 | financing_contract, date, currency, project, analytic_line = zip(data) |
16 | 113 | else: | 118 | else: |
17 | 114 | accounting_code, description, second_description, third, expense, receipt, project, financing_line, \ | 119 | accounting_code, description, second_description, third, expense, receipt, project, financing_line, \ |
18 | 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) |
19 | 121 | |||
20 | 122 | # get active cc and dest args before searching | ||
21 | 123 | aaa_obj = self.pool.get('account.analytic.account') | ||
22 | 124 | date_args = aaa_obj._search_filter_active(cr, uid, [], None, [('filter_active', '=', True)], context=context) | ||
23 | 125 | |||
24 | 126 | #US-671: ONLY APPLY FOR THE SAGA THAT CONTAINS Project and Axis1 columns: Retrieve DEST and CC from the Project and axis1 columns | ||
25 | 127 | if project and project[0]: | ||
26 | 128 | # check if the project value exists as a valid costcenter in the local system | ||
27 | 129 | condition = [('category', '=', 'OC'),('type', '!=', 'view'), ('state', '=', 'open'),('code', '=ilike', project[0]),] | ||
28 | 130 | condition.extend(date_args) | ||
29 | 131 | cc_ids = aaa_obj.search(cr, uid, condition, context=context) | ||
30 | 132 | if cc_ids and cc_ids[0]: | ||
31 | 133 | cost_center_id = cc_ids[0] | ||
32 | 134 | else: | ||
33 | 135 | error_message = "Invalid Cost Center [" + project[0] + "] will be ignored. " | ||
34 | 136 | if axis1 and axis1[0]: | ||
35 | 137 | # check if the value exists as a valid DEST in the local system | ||
36 | 138 | condition = [('category', '=', 'DEST'),('type', '!=', 'view'),('code', '=ilike', axis1[0]),] | ||
37 | 139 | date_args.extend(condition) | ||
38 | 140 | dest_ids = aaa_obj.search(cr, uid, date_args, context=context) | ||
39 | 141 | if dest_ids and dest_ids[0]: | ||
40 | 142 | destination_id = dest_ids[0] | ||
41 | 143 | else: | ||
42 | 144 | error_message = error_message + "Invalid Destination [" + axis1[0] + "] will be ignored." | ||
43 | 145 | |||
44 | 116 | # Check period | 146 | # Check period |
45 | 117 | if not date and not date[0]: | 147 | if not date and not date[0]: |
46 | 118 | raise osv.except_osv(_('Warning'), _('A date is missing!')) | 148 | raise osv.except_osv(_('Warning'), _('A date is missing!')) |
47 | @@ -140,6 +170,7 @@ | |||
48 | 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]),)) |
49 | 141 | if len(account_ids) > 1: | 171 | if len(account_ids) > 1: |
50 | 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]),)) |
51 | 173 | |||
52 | 143 | # Fetch DEBIT/CREDIT | 174 | # Fetch DEBIT/CREDIT |
53 | 144 | debit = 0.0 | 175 | debit = 0.0 |
54 | 145 | credit = 0.0 | 176 | credit = 0.0 |
55 | @@ -199,7 +230,10 @@ | |||
56 | 199 | # US_263: get employee destination, if haven't get default destination | 230 | # US_263: get employee destination, if haven't get default destination |
57 | 200 | if employee_id: | 231 | if employee_id: |
58 | 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) |
60 | 202 | if emp.destination_id: | 233 | if destination_id and destination_id != emp.destination_id.id: |
61 | 234 | to_update_employee = True # turn the flag to update the employee | ||
62 | 235 | |||
63 | 236 | if not destination_id and emp.destination_id: # US-671: Only update if the destination from the import is not valid | ||
64 | 203 | destination_id = emp.destination_id.id | 237 | destination_id = emp.destination_id.id |
65 | 204 | if not destination_id: | 238 | if not destination_id: |
66 | 205 | if not account.default_destination_id: | 239 | if not account.default_destination_id: |
67 | @@ -241,21 +275,33 @@ | |||
68 | 241 | # Retrieve analytic distribution from employee | 275 | # Retrieve analytic distribution from employee |
69 | 242 | if employee_id: | 276 | if employee_id: |
70 | 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']) |
71 | 278 | #US-671: use the cost center from the import, if not retrieve from employee | ||
72 | 279 | temp_cc = employee_data and employee_data.get('cost_center_id', False) and employee_data.get('cost_center_id')[0] or False | ||
73 | 280 | if cost_center_id and cost_center_id != temp_cc: | ||
74 | 281 | to_update_employee =True | ||
75 | 282 | if not cost_center_id: | ||
76 | 283 | cost_center_id = temp_cc | ||
77 | 244 | vals.update({ | 284 | vals.update({ |
79 | 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, |
80 | 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, |
81 | 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, |
82 | 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, |
83 | 249 | }) | 289 | }) |
84 | 250 | # Write payroll entry | 290 | # Write payroll entry |
85 | 251 | if wiz_state != 'simu': | 291 | if wiz_state != 'simu': |
86 | 292 | #US-671: In the process mode, update the employee cost center and destination, and use also this one for the payroll object. | ||
87 | 293 | ############################ UPDATE THE EMPLOYEE! AND PREPARE THE LOG FILE WITH WARNING! | ||
88 | 294 | if to_update_employee and employee_id: | ||
89 | 295 | self.pool.get('hr.employee').write(cr, uid, [employee_id], {'cost_center_id': cost_center_id, 'destination_id': destination_id,}, context) | ||
90 | 296 | |||
91 | 252 | res = self.pool.get('hr.payroll.msf').create(cr, uid, vals, | 297 | res = self.pool.get('hr.payroll.msf').create(cr, uid, vals, |
92 | 253 | context={'from': 'import'}) | 298 | context={'from': 'import'}) |
93 | 254 | if res: | 299 | if res: |
94 | 255 | created += 1 | 300 | created += 1 |
95 | 256 | else: | 301 | else: |
96 | 257 | created += 1 | 302 | created += 1 |
98 | 258 | return True, amount, created, vals, currency[0] | 303 | msg = 'Duy Test' |
99 | 304 | return True, amount, created, vals, currency[0], error_message | ||
100 | 259 | 305 | ||
101 | 260 | def _get_homere_password(self, cr, uid, pass_type='payroll'): | 306 | def _get_homere_password(self, cr, uid, pass_type='payroll'): |
102 | 261 | ##### UPDATE HOMERE.CONF FILE ##### | 307 | ##### UPDATE HOMERE.CONF FILE ##### |
103 | @@ -477,9 +523,10 @@ | |||
104 | 477 | res = True | 523 | res = True |
105 | 478 | res_amount = 0.0 | 524 | res_amount = 0.0 |
106 | 479 | amount = 0.0 | 525 | amount = 0.0 |
107 | 526 | error_msg = "" | ||
108 | 480 | for line in reader: | 527 | for line in reader: |
109 | 481 | processed += 1 | 528 | processed += 1 |
111 | 482 | update, amount, nb_created, vals, ccy = self.update_payroll_entries( | 529 | update, amount, nb_created, vals, ccy, msg = self.update_payroll_entries( |
112 | 483 | cr, uid, data=line, field=field, | 530 | cr, uid, data=line, field=field, |
113 | 484 | date_format=wiz.date_format, | 531 | date_format=wiz.date_format, |
114 | 485 | wiz_state=wiz.state) | 532 | wiz_state=wiz.state) |
115 | @@ -490,6 +537,10 @@ | |||
116 | 490 | header_vals = vals | 537 | header_vals = vals |
117 | 491 | header_vals['currency_code'] = ccy | 538 | header_vals['currency_code'] = ccy |
118 | 492 | created += nb_created | 539 | created += nb_created |
119 | 540 | |||
120 | 541 | if msg: | ||
121 | 542 | error_msg += "Line " + str(processed) + ": " + msg + " \n" | ||
122 | 543 | |||
123 | 493 | # Check balance | 544 | # Check balance |
124 | 494 | res_amount_rounded = round(res_amount, 2) | 545 | res_amount_rounded = round(res_amount, 2) |
125 | 495 | if res_amount_rounded != 0.0: | 546 | if res_amount_rounded != 0.0: |
126 | @@ -536,7 +587,13 @@ | |||
127 | 536 | 587 | ||
128 | 537 | if wiz_state == 'simu' and ids: | 588 | if wiz_state == 'simu' and ids: |
129 | 538 | # US_201: if check raise no error, change state to process | 589 | # US_201: if check raise no error, change state to process |
131 | 539 | self.write(cr, uid, [wiz.id], {'state': 'proceed'}) | 590 | # US-671: Show message in the wizard if there was warning or not. |
132 | 591 | if error_msg: | ||
133 | 592 | error_msg = "Import can be processed but with the following warnings:\n-------------------- \n" + error_msg | ||
134 | 593 | else: | ||
135 | 594 | error_msg = "No warning found for this file. Import can be now processed." | ||
136 | 595 | |||
137 | 596 | self.write(cr, uid, [wiz.id], {'state': 'proceed', 'msg': error_msg}) | ||
138 | 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, |
139 | 541 | uid, 'msf_homere_interface', 'payroll_import_wizard') | 598 | uid, 'msf_homere_interface', 'payroll_import_wizard') |
140 | 542 | view_id = view_id and view_id[1] or False | 599 | view_id = view_id and view_id[1] or False |
141 | @@ -563,7 +620,7 @@ | |||
142 | 563 | # This is to redirect to Payroll Tree View | 620 | # This is to redirect to Payroll Tree View |
143 | 564 | context.update({'from': 'payroll_import'}) | 621 | context.update({'from': 'payroll_import'}) |
144 | 565 | 622 | ||
146 | 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) |
147 | 567 | 624 | ||
148 | 568 | return { | 625 | return { |
149 | 569 | 'name': 'Payroll Import Confirmation', | 626 | 'name': 'Payroll Import Confirmation', |