~gs.clearcorp/openerp-costa-rica/7.0_l10n_cr_hr_payroll_pay_generator_bac

« back to all changes in this revision

Viewing changes to l10n_cr_hr_payroll_pay_generator_bac/report/l10n_cr_hr_payroll_pay_generator_bac_report.py

  • Committer: Glen Sojo
  • Date: 2014-06-25 22:29:56 UTC
  • Revision ID: glen.sojo@clearcorp.co.cr-20140625222956-z5537rvwz7otay7f
[ADD] - l10n_cr_hr_payroll_pay_generator_bac: Added new module to generate Bac San Jose payments.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
##############################################################################
 
3
#
 
4
#    OpenERP, Open Source Management Solution
 
5
#    Addons modules by CLEARCORP S.A.
 
6
#    Copyright (C) 2009-TODAY CLEARCORP S.A. (<http://clearcorp.co.cr>).
 
7
#
 
8
#    This program is free software: you can redistribute it and/or modify
 
9
#    it under the terms of the GNU Affero General Public License as
 
10
#    published by the Free Software Foundation, either version 3 of the
 
11
#    License, or (at your option) any later version.
 
12
#
 
13
#    This program is distributed in the hope that it will be useful,
 
14
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
#    GNU Affero General Public License for more details.
 
17
#
 
18
#    You should have received a copy of the GNU Affero General Public License
 
19
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
20
#
 
21
##############################################################################
 
22
 
 
23
from report import report_sxw
 
24
from report.report_sxw import rml_parse
 
25
import openerp.pooler as pooler
 
26
from openerp.tools.translate import _
 
27
 
 
28
class Parser(report_sxw.rml_parse):
 
29
    def __init__(self, cr, uid, name, context):
 
30
        super(Parser, self).__init__(cr, uid, name, context)
 
31
        self.cursor = cr
 
32
        self.pool = pooler.get_pool(cr.dbname)
 
33
        self.localcontext.update({
 
34
            'get_label_name': self.get_label_name,
 
35
            'get_label_amount': self.get_label_amount,
 
36
            'get_label_account': self.get_label_account,
 
37
            'compute_payslip_lines': self.compute_payslip_lines,
 
38
        })
 
39
 
 
40
    def get_label_name(self):
 
41
        return _('Employee Name')
 
42
 
 
43
    def get_label_amount(self):
 
44
        return _('Amount')
 
45
 
 
46
    def get_label_account(self):
 
47
        return _('Bank Account')
 
48
 
 
49
    def compute_payslip_lines(self, data):
 
50
        payslip_run_id = data.get('payslip_run_id', False)
 
51
        if not payslip_run_id: return False
 
52
        employee_ids = data.get('employee_ids', False)
 
53
        if not employee_ids: return False
 
54
        salary_rule_id = data.get('salary_rule_id', False)
 
55
        if not salary_rule_id: return False
 
56
        self.cr.execute("""SELECT EMP.name_related AS employee_name,
 
57
  CASE WHEN EMP.bank_account_id IS NULL THEN ''
 
58
       ELSE
 
59
         (SELECT BANK.acc_number
 
60
         FROM res_partner_bank AS BANK
 
61
         WHERE EMP.bank_account_id = BANK.id
 
62
         LIMIT 1)
 
63
  END as acc_number,
 
64
  CASE WHEN
 
65
    (SELECT SUM(LINE.amount)
 
66
    FROM hr_payslip_line AS LINE
 
67
    WHERE LINE.slip_id = PAYSLIP.id AND
 
68
      LINE.salary_rule_id = %s) IS NULL THEN 0.0
 
69
  ELSE
 
70
    (SELECT SUM(LINE.amount)
 
71
    FROM hr_payslip_line AS LINE
 
72
    WHERE LINE.slip_id = PAYSLIP.id AND
 
73
      LINE.salary_rule_id = %s)
 
74
  END AS amount
 
75
FROM hr_employee as EMP,
 
76
  hr_payslip as PAYSLIP,
 
77
  hr_payslip_run as BATCH
 
78
WHERE EMP.id in %s AND
 
79
  EMP.id = PAYSLIP.employee_id AND
 
80
  BATCH.id = PAYSLIP.payslip_run_id AND
 
81
  BATCH.id = %s""",[salary_rule_id, salary_rule_id, tuple(employee_ids), payslip_run_id])
 
82
        result = self.cr.dictfetchall()
 
83
        return result
 
 
b'\\ No newline at end of file'