[MERGE] Sync with trunk.
[odoo/odoo.git] / addons / l10n_in_hr_payroll / wizard / hr_salary_employee_bymonth.py
1 #-*- coding:utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2011 OpenERP SA (<http://openerp.com>). All Rights Reserved
6 #
7 #    This program is free software: you can redistribute it and/or modify
8 #    it under the terms of the GNU Affero General Public License as published by
9 #    the Free Software Foundation, either version 3 of the License, or
10 #    (at your option) any later version.
11 #
12 #    This program is distributed in the hope that it will be useful,
13 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
14 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 #    GNU Affero General Public License for more details.
16 #
17 #    You should have received a copy of the GNU Affero General Public License
18 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 #
20 ##############################################################################
21
22 import time
23
24 from openerp.osv import fields, osv
25
26 class hr_salary_employee_bymonth(osv.osv_memory):
27
28     _name = 'hr.salary.employee.month'
29     _description = 'Hr Salary Employee By Month Report'
30     _columns = {
31         'start_date': fields.date('Start Date', required=True),
32         'end_date': fields.date('End Date', required=True),
33         'employee_ids': fields.many2many('hr.employee', 'payroll_year_rel', 'payroll_year_id', 'employee_id', 'Employees', required=True),
34         'category_id': fields.many2one('hr.salary.rule.category', 'Category', required=True),
35     }
36
37     def _get_default_category(self, cr, uid, context=None):
38         category_ids = self.pool.get('hr.salary.rule.category').search(cr, uid, [('code', '=', 'NET')], context=context)
39         return category_ids and category_ids[0] or False
40
41     _defaults = {
42          'start_date': lambda *a: time.strftime('%Y-01-01'),
43          'end_date': lambda *a: time.strftime('%Y-%m-%d'),
44          'category_id': _get_default_category
45     }
46
47     def print_report(self, cr, uid, ids, context=None):
48         """
49          To get the date and print the report
50          @param self: The object pointer.
51          @param cr: A database cursor
52          @param uid: ID of the user currently logged in
53          @param context: A standard dictionary
54          @return: return report
55         """
56         if context is None:
57             context = {}
58         datas = {'ids': context.get('active_ids', [])}
59
60         res = self.read(cr, uid, ids, context=context)
61         res = res and res[0] or {}
62         datas.update({'form': res})
63         return {
64             'type': 'ir.actions.report.xml',
65             'report_name': 'salary.employee.bymonth',
66             'datas': datas,
67        }
68
69 hr_salary_employee_bymonth()
70
71 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: