Merge lp:~inddiana/sisb/sisb_nomina_resumen_reporte_gastos into lp:sisb
- sisb_nomina_resumen_reporte_gastos
- Merge into sisb
Proposed by
[SISB] Aryrosa Fuentes
Status: | Merged |
---|---|
Merged at revision: | 985 |
Proposed branch: | lp:~inddiana/sisb/sisb_nomina_resumen_reporte_gastos |
Merge into: | lp:sisb |
Diff against target: |
558 lines (+502/-0) 10 files modified
sisb_nomina_resumen/__init__.py (+1/-0) sisb_nomina_resumen/__openerp__.py (+42/-0) sisb_nomina_resumen/i18n/es_VE.po (+109/-0) sisb_nomina_resumen/report/__init__.py (+1/-0) sisb_nomina_resumen/report/report_nomina_resumen.py (+35/-0) sisb_nomina_resumen/security/groups.xml (+20/-0) sisb_nomina_resumen/security/ir.model.access.csv (+2/-0) sisb_nomina_resumen/wizard/__init__.py (+1/-0) sisb_nomina_resumen/wizard/sisb_nomina_resumen.py (+253/-0) sisb_nomina_resumen/wizard/sisb_nomina_resumen_wizard.xml (+38/-0) |
To merge this branch: | bzr merge lp:~inddiana/sisb/sisb_nomina_resumen_reporte_gastos |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Juan Lugo | Pending | ||
Review via email: mp+337282@code.launchpad.net |
Commit message
Description of the change
[IMP] se creo el modulo sisb_nomina_resumen para generar un reporte de los gasto de nominas por mes.
[FIX] Ajsutes en el reporte con respecto a la forma de obtener la fecha de inicio de la relacion laboral. Se asume que en sisb_nomina ya existe la funcion que realiza el calculo.
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 | === added directory 'sisb_nomina_resumen' | |||
2 | === added file 'sisb_nomina_resumen/__init__.py' | |||
3 | --- sisb_nomina_resumen/__init__.py 1970-01-01 00:00:00 +0000 | |||
4 | +++ sisb_nomina_resumen/__init__.py 2018-02-07 15:37:15 +0000 | |||
5 | @@ -0,0 +1,1 @@ | |||
6 | 1 | import wizard, report | ||
7 | 0 | 2 | ||
8 | === added file 'sisb_nomina_resumen/__openerp__.py' | |||
9 | --- sisb_nomina_resumen/__openerp__.py 1970-01-01 00:00:00 +0000 | |||
10 | +++ sisb_nomina_resumen/__openerp__.py 2018-02-07 15:37:15 +0000 | |||
11 | @@ -0,0 +1,42 @@ | |||
12 | 1 | # -*- coding:utf-8 -*- | ||
13 | 2 | ############################################################################## | ||
14 | 3 | # | ||
15 | 4 | # SISB, Sistema Integral Simon Bolivar | ||
16 | 5 | # Copyright (C) 2012-2013 Industrias Diana, C.A. All Rights Reserved | ||
17 | 6 | # | ||
18 | 7 | # This program is free software: you can redistribute it and/or modify | ||
19 | 8 | # it under the terms of the GNU Affero General Public License as published by | ||
20 | 9 | # the Free Software Foundation, either version 3 of the License, or | ||
21 | 10 | # (at your option) any later version. | ||
22 | 11 | # | ||
23 | 12 | # This program is distributed in the hope that it will be useful, | ||
24 | 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
25 | 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
26 | 15 | # GNU Affero General Public License for more details. | ||
27 | 16 | # | ||
28 | 17 | # You should have received a copy of the GNU Affero General Public License | ||
29 | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
30 | 19 | # | ||
31 | 20 | ############################################################################## | ||
32 | 21 | { | ||
33 | 22 | 'name': 'Resumen general de asignaciones y deducciones de nomina.', | ||
34 | 23 | 'version': '1.0', | ||
35 | 24 | "author": "Industrias Diana C.A.", | ||
36 | 25 | "category": "Human Resources", | ||
37 | 26 | "website": "http://www.industriasdiana.gob.ve", | ||
38 | 27 | 'description': """Modulo que genera un reporte general con todas las asignaciones y deducciones de todos | ||
39 | 28 | los trabajadores, clasificandolos por el tipo de nomina, en formato .ods y protegido | ||
40 | 29 | contra escritura.""", | ||
41 | 30 | 'depends': ['base', 'sisb_nomina'], | ||
42 | 31 | 'external_dependencies': { | ||
43 | 32 | 'python': ['xlwt'] | ||
44 | 33 | }, | ||
45 | 34 | 'init_xml': [], | ||
46 | 35 | 'update_xml': [ | ||
47 | 36 | 'security/groups.xml', | ||
48 | 37 | 'security/ir.model.access.csv', | ||
49 | 38 | 'wizard/sisb_nomina_resumen_wizard.xml' | ||
50 | 39 | ], | ||
51 | 40 | 'active': True, | ||
52 | 41 | 'installable': True | ||
53 | 42 | } | ||
54 | 0 | 43 | ||
55 | === added directory 'sisb_nomina_resumen/i18n' | |||
56 | === added file 'sisb_nomina_resumen/i18n/es_VE.mo' | |||
57 | 1 | Binary files sisb_nomina_resumen/i18n/es_VE.mo 1970-01-01 00:00:00 +0000 and sisb_nomina_resumen/i18n/es_VE.mo 2018-02-07 15:37:15 +0000 differ | 44 | Binary files sisb_nomina_resumen/i18n/es_VE.mo 1970-01-01 00:00:00 +0000 and sisb_nomina_resumen/i18n/es_VE.mo 2018-02-07 15:37:15 +0000 differ |
58 | === added file 'sisb_nomina_resumen/i18n/es_VE.po' | |||
59 | --- sisb_nomina_resumen/i18n/es_VE.po 1970-01-01 00:00:00 +0000 | |||
60 | +++ sisb_nomina_resumen/i18n/es_VE.po 2018-02-07 15:37:15 +0000 | |||
61 | @@ -0,0 +1,109 @@ | |||
62 | 1 | # Translation of OpenERP Server. | ||
63 | 2 | # This file contains the translation of the following modules: | ||
64 | 3 | # * sisb_nomina_resumen | ||
65 | 4 | # | ||
66 | 5 | msgid "" | ||
67 | 6 | msgstr "" | ||
68 | 7 | "Project-Id-Version: OpenERP Server 6.0.4\n" | ||
69 | 8 | "Report-Msgid-Bugs-To: support@openerp.com\n" | ||
70 | 9 | "POT-Creation-Date: 2017-05-10 13:33+0000\n" | ||
71 | 10 | "PO-Revision-Date: 2017-05-10 09:37-0400\n" | ||
72 | 11 | "Last-Translator: carmelo <carmelolopez3@hotmail.com>\n" | ||
73 | 12 | "Language-Team: \n" | ||
74 | 13 | "MIME-Version: 1.0\n" | ||
75 | 14 | "Content-Type: text/plain; charset=UTF-8\n" | ||
76 | 15 | "Content-Transfer-Encoding: 8bit\n" | ||
77 | 16 | "Plural-Forms: \n" | ||
78 | 17 | |||
79 | 18 | #. module: sisb_nomina_resumen | ||
80 | 19 | #: code:addons/sisb_nomina_resumen/wizard/sisb_nomina_resumen.py:190 | ||
81 | 20 | #, python-format | ||
82 | 21 | msgid "Net Total" | ||
83 | 22 | msgstr "Total Neto" | ||
84 | 23 | |||
85 | 24 | #. module: sisb_nomina_resumen | ||
86 | 25 | #: code:addons/sisb_nomina_resumen/wizard/sisb_nomina_resumen.py:157 | ||
87 | 26 | #, python-format | ||
88 | 27 | msgid "Roster" | ||
89 | 28 | msgstr "Nómina" | ||
90 | 29 | |||
91 | 30 | #. module: sisb_nomina_resumen | ||
92 | 31 | #: view:sisb.nomina.resumen:0 | ||
93 | 32 | msgid "Print" | ||
94 | 33 | msgstr "Imprimir" | ||
95 | 34 | |||
96 | 35 | #. module: sisb_nomina_resumen | ||
97 | 36 | #: code:addons/sisb_nomina_resumen/wizard/sisb_nomina_resumen.py:220 | ||
98 | 37 | #, python-format | ||
99 | 38 | msgid "roster_report_" | ||
100 | 39 | msgstr "reporte_nomina_" | ||
101 | 40 | |||
102 | 41 | #. module: sisb_nomina_resumen | ||
103 | 42 | #: model:ir.actions.act_window,name:sisb_nomina_resumen.action_wizard_sisb_nomina_resumen | ||
104 | 43 | #: model:ir.ui.menu,name:sisb_nomina_resumen.menu_wizard_sisb_nomina_resumen | ||
105 | 44 | msgid "Resumen mensual de nomina" | ||
106 | 45 | msgstr "Resumen mensual de nomina" | ||
107 | 46 | |||
108 | 47 | #. module: sisb_nomina_resumen | ||
109 | 48 | #: model:ir.actions.report.xml,name:sisb_nomina_resumen.report_nomina_resumen | ||
110 | 49 | msgid "Reporte de nomina" | ||
111 | 50 | msgstr "Reporte de nomina" | ||
112 | 51 | |||
113 | 52 | #. module: sisb_nomina_resumen | ||
114 | 53 | #: code:addons/sisb_nomina_resumen/wizard/sisb_nomina_resumen.py:177 | ||
115 | 54 | #, python-format | ||
116 | 55 | msgid "Total bonuses" | ||
117 | 56 | msgstr "Total Asignaciones" | ||
118 | 57 | |||
119 | 58 | #. module: sisb_nomina_resumen | ||
120 | 59 | #: field:sisb.nomina.resumen,month:0 | ||
121 | 60 | msgid "Month" | ||
122 | 61 | msgstr "Mes" | ||
123 | 62 | |||
124 | 63 | #. module: sisb_nomina_resumen | ||
125 | 64 | #: code:addons/sisb_nomina_resumen/wizard/sisb_nomina_resumen.py:158 | ||
126 | 65 | #, python-format | ||
127 | 66 | msgid "Employee" | ||
128 | 67 | msgstr "Empleado" | ||
129 | 68 | |||
130 | 69 | #. module: sisb_nomina_resumen | ||
131 | 70 | #: code:addons/sisb_nomina_resumen/wizard/sisb_nomina_resumen.py:162 | ||
132 | 71 | #, python-format | ||
133 | 72 | msgid "Job" | ||
134 | 73 | msgstr "Cargo" | ||
135 | 74 | |||
136 | 75 | #. module: sisb_nomina_resumen | ||
137 | 76 | #: code:addons/sisb_nomina_resumen/wizard/sisb_nomina_resumen.py:159 | ||
138 | 77 | #, python-format | ||
139 | 78 | msgid "Identification" | ||
140 | 79 | msgstr "Cédula" | ||
141 | 80 | |||
142 | 81 | #. module: sisb_nomina_resumen | ||
143 | 82 | #: code:addons/sisb_nomina_resumen/wizard/sisb_nomina_resumen.py:160 | ||
144 | 83 | #, python-format | ||
145 | 84 | msgid "Join date" | ||
146 | 85 | msgstr "Fecha Ingreso" | ||
147 | 86 | |||
148 | 87 | #. module: sisb_nomina_resumen | ||
149 | 88 | #: code:addons/sisb_nomina_resumen/wizard/sisb_nomina_resumen.py:161 | ||
150 | 89 | #, python-format | ||
151 | 90 | msgid "Department" | ||
152 | 91 | msgstr "Departamento" | ||
153 | 92 | |||
154 | 93 | #. module: sisb_nomina_resumen | ||
155 | 94 | #: model:ir.model,name:sisb_nomina_resumen.model_sisb_nomina_resumen | ||
156 | 95 | msgid "sisb.nomina.resumen" | ||
157 | 96 | msgstr "sisb.nomina.resumen" | ||
158 | 97 | |||
159 | 98 | #. module: sisb_nomina_resumen | ||
160 | 99 | #: code:addons/sisb_nomina_resumen/wizard/sisb_nomina_resumen.py:223 | ||
161 | 100 | #, python-format | ||
162 | 101 | msgid "No data found" | ||
163 | 102 | msgstr "No se encontró información" | ||
164 | 103 | |||
165 | 104 | #. module: sisb_nomina_resumen | ||
166 | 105 | #: code:addons/sisb_nomina_resumen/wizard/sisb_nomina_resumen.py:186 | ||
167 | 106 | #, python-format | ||
168 | 107 | msgid "Total debts" | ||
169 | 108 | msgstr "Total Deducciones" | ||
170 | 109 | |||
171 | 0 | 110 | ||
172 | === added directory 'sisb_nomina_resumen/report' | |||
173 | === added file 'sisb_nomina_resumen/report/__init__.py' | |||
174 | --- sisb_nomina_resumen/report/__init__.py 1970-01-01 00:00:00 +0000 | |||
175 | +++ sisb_nomina_resumen/report/__init__.py 2018-02-07 15:37:15 +0000 | |||
176 | @@ -0,0 +1,1 @@ | |||
177 | 1 | import report_nomina_resumen | ||
178 | 0 | 2 | ||
179 | === added file 'sisb_nomina_resumen/report/report_nomina_resumen.py' | |||
180 | --- sisb_nomina_resumen/report/report_nomina_resumen.py 1970-01-01 00:00:00 +0000 | |||
181 | +++ sisb_nomina_resumen/report/report_nomina_resumen.py 2018-02-07 15:37:15 +0000 | |||
182 | @@ -0,0 +1,35 @@ | |||
183 | 1 | #!/usr/bin/env python | ||
184 | 2 | # -*- coding: utf-8 -*- | ||
185 | 3 | from report import report_sxw | ||
186 | 4 | import os | ||
187 | 5 | |||
188 | 6 | |||
189 | 7 | class report_nomina_resumen(report_sxw.rml_parse): | ||
190 | 8 | """ Herencia a clase base para reportes de OpenERP | ||
191 | 9 | """ | ||
192 | 10 | _name = 'report.nomina.resumen' | ||
193 | 11 | |||
194 | 12 | def __init__(self, cr, uid, name, context): | ||
195 | 13 | """ Se sobrecarga el init para agregarle el context | ||
196 | 14 | """ | ||
197 | 15 | super(report_nomina_resumen, self).__init__(cr, uid, name, context) | ||
198 | 16 | self.context = context | ||
199 | 17 | |||
200 | 18 | |||
201 | 19 | report_sxw = report_sxw.report_sxw | ||
202 | 20 | |||
203 | 21 | |||
204 | 22 | class TxtParser(report_sxw): | ||
205 | 23 | def __init__(self, name, table, rml=False, parser=False, header=True, store=False): | ||
206 | 24 | self.parser_instance = False | ||
207 | 25 | self.localcontext = {} | ||
208 | 26 | report_sxw.__init__(self, name, table, rml, parser, header, store) | ||
209 | 27 | |||
210 | 28 | def create_single_pdf(self, cursor, uid, ids, data, report_xml, context): | ||
211 | 29 | file = open(data['file'], 'r') | ||
212 | 30 | output = file.read() | ||
213 | 31 | os.remove(data['file']) | ||
214 | 32 | return (output, 'ods') | ||
215 | 33 | |||
216 | 34 | |||
217 | 35 | TxtParser('report.nomina.resumen', 'nomina.resumen', None, parser=report_nomina_resumen, header=False) | ||
218 | 0 | 36 | ||
219 | === added directory 'sisb_nomina_resumen/security' | |||
220 | === added file 'sisb_nomina_resumen/security/groups.xml' | |||
221 | --- sisb_nomina_resumen/security/groups.xml 1970-01-01 00:00:00 +0000 | |||
222 | +++ sisb_nomina_resumen/security/groups.xml 2018-02-07 15:37:15 +0000 | |||
223 | @@ -0,0 +1,20 @@ | |||
224 | 1 | <?xml version="1.0" encoding="utf-8"?> | ||
225 | 2 | <openerp> | ||
226 | 3 | <data noupdate="0"> | ||
227 | 4 | <!-- Groups --> | ||
228 | 5 | <record id="group_sisb_nomina_resumen" model="res.groups"> | ||
229 | 6 | <field name="name">Nomina / Reporte Mensual</field> | ||
230 | 7 | </record> | ||
231 | 8 | <!-- Access to menues --> | ||
232 | 9 | <record model="ir.ui.menu" id="hr.menu_hr_root"> | ||
233 | 10 | <field eval="[(4, ref('group_sisb_nomina_resumen'))]" name="groups_id"/> | ||
234 | 11 | </record> | ||
235 | 12 | |||
236 | 13 | <record model="ir.ui.menu" id="hr.menu_hr_reporting"> | ||
237 | 14 | <field eval="[(4, ref('group_sisb_nomina_resumen'))]" name="groups_id"/> | ||
238 | 15 | </record> | ||
239 | 16 | <record model="ir.ui.menu" id="sisb_nomina.menu_hr_payroll_reporting"> | ||
240 | 17 | <field eval="[(4, ref('group_sisb_nomina_resumen'))]" name="groups_id"/> | ||
241 | 18 | </record> | ||
242 | 19 | </data> | ||
243 | 20 | </openerp> | ||
244 | 0 | 21 | ||
245 | === added file 'sisb_nomina_resumen/security/ir.model.access.csv' | |||
246 | --- sisb_nomina_resumen/security/ir.model.access.csv 1970-01-01 00:00:00 +0000 | |||
247 | +++ sisb_nomina_resumen/security/ir.model.access.csv 2018-02-07 15:37:15 +0000 | |||
248 | @@ -0,0 +1,2 @@ | |||
249 | 1 | id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink | ||
250 | 2 | access_sisb_nomina_resumen_hr_month,Resumen Nomina: hr.month,sisb_nomina.model_hr_month,group_sisb_nomina_resumen,1,0,0,0 | ||
251 | 0 | 3 | ||
252 | === added directory 'sisb_nomina_resumen/wizard' | |||
253 | === added file 'sisb_nomina_resumen/wizard/__init__.py' | |||
254 | --- sisb_nomina_resumen/wizard/__init__.py 1970-01-01 00:00:00 +0000 | |||
255 | +++ sisb_nomina_resumen/wizard/__init__.py 2018-02-07 15:37:15 +0000 | |||
256 | @@ -0,0 +1,1 @@ | |||
257 | 1 | import sisb_nomina_resumen | ||
258 | 0 | 2 | ||
259 | === added file 'sisb_nomina_resumen/wizard/sisb_nomina_resumen.py' | |||
260 | --- sisb_nomina_resumen/wizard/sisb_nomina_resumen.py 1970-01-01 00:00:00 +0000 | |||
261 | +++ sisb_nomina_resumen/wizard/sisb_nomina_resumen.py 2018-02-07 15:37:15 +0000 | |||
262 | @@ -0,0 +1,253 @@ | |||
263 | 1 | #!/usr/bin/env python | ||
264 | 2 | # -*- coding: utf-8 -*- | ||
265 | 3 | """Modelos del modulo :Resumen mensual de nomina:""" | ||
266 | 4 | from osv import fields, osv | ||
267 | 5 | from tools.translate import _ | ||
268 | 6 | from datetime import datetime | ||
269 | 7 | import xlwt | ||
270 | 8 | |||
271 | 9 | |||
272 | 10 | class FitCol(object): | ||
273 | 11 | """Ajusta el ancho de las columnas automaticamente""" | ||
274 | 12 | |||
275 | 13 | def __init__(self, sheet): | ||
276 | 14 | self.sheet = sheet | ||
277 | 15 | self.widths = dict() | ||
278 | 16 | |||
279 | 17 | def write(self, r, c, label='', *args, **kwargs): | ||
280 | 18 | if isinstance(label, str) and len(args) == 0: | ||
281 | 19 | data = label.decode('utf-8') | ||
282 | 20 | elif isinstance(label, str) and len(args) > 0: | ||
283 | 21 | data = datetime.strptime(label, '%Y-%m-%d') | ||
284 | 22 | else: | ||
285 | 23 | data = label | ||
286 | 24 | self.sheet.write(r, c, data, *args, **kwargs) | ||
287 | 25 | if isinstance(label, (int, float)): | ||
288 | 26 | label = str(label).decode('utf-8') | ||
289 | 27 | width = (len(label) + 1) * 256 | ||
290 | 28 | if width > self.widths.get(c, 0): | ||
291 | 29 | self.widths[c] = width | ||
292 | 30 | self.sheet.col(c).width = width | ||
293 | 31 | |||
294 | 32 | def __getattr__(self, attr): | ||
295 | 33 | return getattr(self.sheet, attr) | ||
296 | 34 | |||
297 | 35 | |||
298 | 36 | class sisb_nomina_resumen(osv.osv_memory): | ||
299 | 37 | """Asistente para el reporte del resumen de nomina""" | ||
300 | 38 | _name = 'sisb.nomina.resumen' | ||
301 | 39 | _columns = { | ||
302 | 40 | 'month': fields.many2one('hr.month', 'Month', required=True) | ||
303 | 41 | } | ||
304 | 42 | |||
305 | 43 | def get_employees_data(self, cr, month): | ||
306 | 44 | """ Query a Postgres para obtener informacion de los empleados en un mes. | ||
307 | 45 | |||
308 | 46 | :param month: Nombre del mes a consultar. | ||
309 | 47 | """ | ||
310 | 48 | query = ''' | ||
311 | 49 | SELECT | ||
312 | 50 | hde.payroll as nom, | ||
313 | 51 | he.name as emp, | ||
314 | 52 | he.identification_id as ide, | ||
315 | 53 | date_start_rel_laboral(he.id) as dst, | ||
316 | 54 | hde.department_id as dpt, | ||
317 | 55 | hde.job as job, | ||
318 | 56 | case when hpl.type_calc = 'deduction' then 'debt' else 'bonus' end as typ, | ||
319 | 57 | hc.name as con, | ||
320 | 58 | sum(hpl.total) | ||
321 | 59 | FROM | ||
322 | 60 | hr_payslip_line as hpl | ||
323 | 61 | join hr_payslip as hrp on hrp.id = hpl.slip_id | ||
324 | 62 | join hr_employee as he on he.id = hpl.employee_id | ||
325 | 63 | join hr_department_employee as hde on hde.employee_id = he.id | ||
326 | 64 | and hde.date_start < hrp.date_from and (hde.date_end > hrp.date_from or hde.date_end is null) | ||
327 | 65 | join hr_concept as hc on hc.id = hpl.concept_id and hc.type <> 'aporte_patronal' | ||
328 | 66 | join hr_process as hp on hp.id = hpl.process_id and hp.type in ('nomina') | ||
329 | 67 | join hr_period_process_rel as hppr on hppr.process_id = hp.id | ||
330 | 68 | join hr_period as hpe on hpe.id = hppr.period_id | ||
331 | 69 | join hr_month as hm on hm.id = hpe.hr_month_id and hm.name = '%s' | ||
332 | 70 | WHERE appears_on_payslip = True | ||
333 | 71 | group by emp, con, typ, ide, nom, dst, dpt, job | ||
334 | 72 | order by emp, typ, con | ||
335 | 73 | ''' % (month) | ||
336 | 74 | |||
337 | 75 | cr.execute(query) | ||
338 | 76 | employees = {} | ||
339 | 77 | for roster, name, identification, join_date, department, job, asign, concept, total in cr.fetchall(): | ||
340 | 78 | if identification not in employees: | ||
341 | 79 | employees[identification] = {} | ||
342 | 80 | employees[identification]['roster'] = roster | ||
343 | 81 | employees[identification]['name'] = name | ||
344 | 82 | employees[identification]['identification'] = identification | ||
345 | 83 | employees[identification]['join_date'] = join_date | ||
346 | 84 | employees[identification]['department'] = department | ||
347 | 85 | employees[identification]['job'] = job | ||
348 | 86 | if 'bonuses' not in employees[identification]: | ||
349 | 87 | employees[identification]['bonuses'] = {} | ||
350 | 88 | if 'debts' not in employees[identification]: | ||
351 | 89 | employees[identification]['debts'] = {} | ||
352 | 90 | if asign == 'bonus': | ||
353 | 91 | employees[identification]['bonuses'][concept] = total | ||
354 | 92 | else: | ||
355 | 93 | employees[identification]['debts'][concept] = total | ||
356 | 94 | |||
357 | 95 | return employees | ||
358 | 96 | |||
359 | 97 | def get_concepts_header(self, cr, month): | ||
360 | 98 | """ Query que se trae todos los conceptos de asignaciones y deducciones de los trabajadores en el mes indicado. | ||
361 | 99 | |||
362 | 100 | :param month: Nombre del mes a consultar. | ||
363 | 101 | """ | ||
364 | 102 | query = ''' | ||
365 | 103 | SELECT | ||
366 | 104 | case when hpl.type_calc = 'deduction' then 'debt' else 'bonus' end as asigned, | ||
367 | 105 | hc.name as concept, | ||
368 | 106 | hc.code as code | ||
369 | 107 | FROM | ||
370 | 108 | hr_payslip_line as hpl | ||
371 | 109 | join hr_employee as he on he.id = hpl.employee_id | ||
372 | 110 | join hr_payroll as hno on hno.id = he.hr_payroll_id | ||
373 | 111 | join hr_concept as hc on hc.id = hpl.concept_id and hc.type <> 'aporte_patronal' | ||
374 | 112 | join hr_process as hp on hp.id = hpl.process_id and hp.type in ('nomina') | ||
375 | 113 | join hr_period_process_rel as hppr on hppr.process_id = hp.id | ||
376 | 114 | join hr_period as hpe on hpe.id = hppr.period_id | ||
377 | 115 | join hr_month as hm on hm.id = hpe.hr_month_id and hm.name = '%s' | ||
378 | 116 | WHERE appears_on_payslip = True | ||
379 | 117 | group by concept, asigned, hc.code | ||
380 | 118 | order by asigned, concept | ||
381 | 119 | ''' % (month) | ||
382 | 120 | |||
383 | 121 | cr.execute(query) | ||
384 | 122 | bonuses = [''] | ||
385 | 123 | debts = [] | ||
386 | 124 | for row in cr.fetchall(): | ||
387 | 125 | con_type, concept, code = row | ||
388 | 126 | if con_type == 'bonus': | ||
389 | 127 | if code == '0100': | ||
390 | 128 | bonuses[0] = concept | ||
391 | 129 | else: | ||
392 | 130 | bonuses.append(concept) | ||
393 | 131 | else: | ||
394 | 132 | debts.append(concept) | ||
395 | 133 | |||
396 | 134 | return {'bonuses': bonuses, 'debts': debts} | ||
397 | 135 | |||
398 | 136 | def get_payrolls_pages(self, cr, month): | ||
399 | 137 | """ Query que se trae los nombres de las nominas de los trabajadores del mes indicado. | ||
400 | 138 | |||
401 | 139 | :param month: Nombre del mes a consultar. | ||
402 | 140 | """ | ||
403 | 141 | query = ''' | ||
404 | 142 | SELECT | ||
405 | 143 | hde.payroll as roster | ||
406 | 144 | FROM | ||
407 | 145 | hr_payslip_line as hpl | ||
408 | 146 | join hr_payslip as hrp on hrp.id = hpl.slip_id | ||
409 | 147 | join hr_employee as he on he.id = hpl.employee_id | ||
410 | 148 | join hr_payroll as hno on hno.id = he.hr_payroll_id | ||
411 | 149 | join hr_department_employee as hde on hde.employee_id = he.id and hde.date_start < hrp.date_from | ||
412 | 150 | and (hde.date_end > hrp.date_from or hde.date_end is null) | ||
413 | 151 | join hr_process as hp on hp.id = hpl.process_id and hp.type in ('nomina') | ||
414 | 152 | join hr_period_process_rel as hppr on hppr.process_id = hp.id | ||
415 | 153 | join hr_period as hpe on hpe.id = hppr.period_id | ||
416 | 154 | join hr_month as hm on hm.id = hpe.hr_month_id and hm.name = '%s' | ||
417 | 155 | WHERE appears_on_payslip = True | ||
418 | 156 | group by roster | ||
419 | 157 | ''' % (month) | ||
420 | 158 | |||
421 | 159 | cr.execute(query) | ||
422 | 160 | return [row[0] for row in cr.fetchall()] | ||
423 | 161 | |||
424 | 162 | def print_results(self, cr, uid, ids, context=None): | ||
425 | 163 | """ Funcion llamada por el wizard para imprimir los resultados. | ||
426 | 164 | """ | ||
427 | 165 | month = self.browse(cr, uid, ids)[0].month.name | ||
428 | 166 | rosters = self.get_payrolls_pages(cr, month) | ||
429 | 167 | doc = xlwt.Workbook() | ||
430 | 168 | pages = {} | ||
431 | 169 | j = {} # Seran los indices de las filas de cada pagina | ||
432 | 170 | for roster in rosters: | ||
433 | 171 | roster = roster[:31] # Por limitaciones de los archivos xls, los nombres de paginas no pueden exceder los 31 caracteres | ||
434 | 172 | # Se crean las paginas y se guardan. Se le van creando las cabeceras | ||
435 | 173 | pages[roster] = doc.add_sheet(roster, True) | ||
436 | 174 | pages[roster].protect = True | ||
437 | 175 | pages[roster] = FitCol(pages[roster]) | ||
438 | 176 | pages[roster].write(0, 0, _('N°')) | ||
439 | 177 | pages[roster].write(0, 1, _('Employee')) | ||
440 | 178 | pages[roster].write(0, 2, _('Identification')) | ||
441 | 179 | pages[roster].write(0, 3, _('Join date')) | ||
442 | 180 | pages[roster].write(0, 4, _('Department')) | ||
443 | 181 | pages[roster].write(0, 5, _('Job')) | ||
444 | 182 | j[roster] = 1 | ||
445 | 183 | |||
446 | 184 | # Se procede a crear las cabeceras de conceptos en cada una de las paginas | ||
447 | 185 | i = 6 # Columns index | ||
448 | 186 | columns = {} | ||
449 | 187 | concepts = self.get_concepts_header(cr, month) | ||
450 | 188 | bonuses = concepts['bonuses'] | ||
451 | 189 | debts = concepts['debts'] | ||
452 | 190 | for bonus in bonuses: | ||
453 | 191 | for page in pages.values(): | ||
454 | 192 | page.write(0, i, bonus) | ||
455 | 193 | columns[bonus] = i | ||
456 | 194 | i += 1 | ||
457 | 195 | for page in pages.values(): | ||
458 | 196 | page.write(0, i, _('Total bonuses')) | ||
459 | 197 | columns['bonuses'] = i | ||
460 | 198 | i += 1 | ||
461 | 199 | for debt in debts: | ||
462 | 200 | for page in pages.values(): | ||
463 | 201 | page.write(0, i, debt) | ||
464 | 202 | columns[debt] = i | ||
465 | 203 | i += 1 | ||
466 | 204 | for page in pages.values(): | ||
467 | 205 | page.write(0, i, _('Total debts')) | ||
468 | 206 | columns['debts'] = i | ||
469 | 207 | i += 1 | ||
470 | 208 | for page in pages.values(): | ||
471 | 209 | page.write(0, i, _('Net Total')) | ||
472 | 210 | columns['net_total'] = i | ||
473 | 211 | |||
474 | 212 | # -------- EMPEZAMOS A LLENAR LA DATA DE LOS TRABAJADORES ------------ | ||
475 | 213 | datas = self.get_employees_data(cr, month) | ||
476 | 214 | date_format = xlwt.XFStyle() | ||
477 | 215 | date_format.num_format_str = 'dd/mm/yyyy' | ||
478 | 216 | currency_format = xlwt.XFStyle() | ||
479 | 217 | currency_format.num_format_str = "#,##0.00" | ||
480 | 218 | for data in datas: | ||
481 | 219 | n = datas[data]['roster'][:31] | ||
482 | 220 | pages[n].write(j[n], 0, j[n]) | ||
483 | 221 | pages[n].write(j[n], 1, datas[data]['name']) | ||
484 | 222 | pages[n].write(j[n], 2, int(datas[data]['identification'])) | ||
485 | 223 | pages[n].write(j[n], 3, datas[data]['join_date'], date_format) | ||
486 | 224 | pages[n].write(j[n], 4, datas[data]['department']) | ||
487 | 225 | pages[n].write(j[n], 5, datas[data]['job']) | ||
488 | 226 | total_bonuses = 0 | ||
489 | 227 | for bonus in datas[data]['bonuses']: | ||
490 | 228 | pages[n].write(j[n], columns[bonus], datas[data]['bonuses'][bonus], currency_format) | ||
491 | 229 | total_bonuses += datas[data]['bonuses'][bonus] | ||
492 | 230 | pages[n].write(j[n], columns['bonuses'], total_bonuses, currency_format) | ||
493 | 231 | total_debts = 0 | ||
494 | 232 | for debt in datas[data]['debts']: | ||
495 | 233 | pages[n].write(j[n], columns[debt], datas[data]['debts'][debt], currency_format) | ||
496 | 234 | total_debts += datas[data]['debts'][debt] | ||
497 | 235 | pages[n].write(j[n], columns['debts'], total_debts, currency_format) | ||
498 | 236 | pages[n].write(j[n], columns['net_total'], total_bonuses - total_debts, currency_format) | ||
499 | 237 | j[n] += 1 | ||
500 | 238 | try: | ||
501 | 239 | file_name = '/tmp/' + _('roster_report_') + datetime.now().strftime('%H%M%S%d%m%Y') | ||
502 | 240 | doc.save(file_name) | ||
503 | 241 | except: | ||
504 | 242 | raise osv.except_osv('ERROR', _('No data found')) | ||
505 | 243 | |||
506 | 244 | data = {} | ||
507 | 245 | data['file'] = file_name | ||
508 | 246 | return { | ||
509 | 247 | 'type': 'ir.actions.report.xml', | ||
510 | 248 | 'report_name': 'nomina.resumen', | ||
511 | 249 | 'datas': data, | ||
512 | 250 | } | ||
513 | 251 | |||
514 | 252 | |||
515 | 253 | sisb_nomina_resumen() | ||
516 | 0 | 254 | ||
517 | === added file 'sisb_nomina_resumen/wizard/sisb_nomina_resumen_wizard.xml' | |||
518 | --- sisb_nomina_resumen/wizard/sisb_nomina_resumen_wizard.xml 1970-01-01 00:00:00 +0000 | |||
519 | +++ sisb_nomina_resumen/wizard/sisb_nomina_resumen_wizard.xml 2018-02-07 15:37:15 +0000 | |||
520 | @@ -0,0 +1,38 @@ | |||
521 | 1 | <?xml version="1.0" encoding="utf-8"?> | ||
522 | 2 | <openerp> | ||
523 | 3 | <data> | ||
524 | 4 | <!-- Wizard view --> | ||
525 | 5 | <record id="view_sisb_nomina_resumen" model="ir.ui.view"> | ||
526 | 6 | <field name="name">sisb.nomina.resumen.form</field> | ||
527 | 7 | <field name="model">sisb.nomina.resumen</field> | ||
528 | 8 | <field name="type">form</field> | ||
529 | 9 | <field name="arch" type="xml"> | ||
530 | 10 | <form> | ||
531 | 11 | <field name="month" /> | ||
532 | 12 | <button name="print_results" string="Print" type="object" icon="gtk-print" /> | ||
533 | 13 | </form> | ||
534 | 14 | </field> | ||
535 | 15 | </record> | ||
536 | 16 | <!-- Action --> | ||
537 | 17 | <record id="action_wizard_sisb_nomina_resumen" model="ir.actions.act_window"> | ||
538 | 18 | <field name="name">Resumen mensual de nomina</field> | ||
539 | 19 | <field name="type">ir.actions.act_window</field> | ||
540 | 20 | <field name="res_model">sisb.nomina.resumen</field> | ||
541 | 21 | <field name="view_type">form</field> | ||
542 | 22 | <field name="view_mode">form</field> | ||
543 | 23 | <field name="target">new</field> | ||
544 | 24 | </record> | ||
545 | 25 | <!-- Report --> | ||
546 | 26 | <report | ||
547 | 27 | auto="False" | ||
548 | 28 | id="report_nomina_resumen" | ||
549 | 29 | model="sisb.nomina.resumen" | ||
550 | 30 | name="nomina.resumen" | ||
551 | 31 | rml="" | ||
552 | 32 | string="Reporte de nomina" | ||
553 | 33 | /> | ||
554 | 34 | <!-- Menu --> | ||
555 | 35 | <menuitem id="menu_wizard_sisb_nomina_resumen" action="action_wizard_sisb_nomina_resumen" | ||
556 | 36 | parent="sisb_nomina.menu_hr_payroll_reporting" name="Resumen mensual de nomina" groups="group_sisb_nomina_resumen" /> | ||
557 | 37 | </data> | ||
558 | 38 | </openerp> |