Commit eb64e687 authored by Santiago Apel's avatar Santiago Apel 💬
Browse files

[FIX] rule_total_max_sub

parent 31c417cb
......@@ -186,6 +186,61 @@ class Payslips(BrowsableObject):
rule_code, months_back, date_to, *args, **kwargs
)
return result
def rule_total_max_sub(self, rule_code,rule_code_sub, months_back,
date_to=False, *args, **kwargs):
"""
Get the max total of totals with a rule given from
date_to (by default payslip date_to or today) to the given months back
"""
query = """SELECT COALESCE(Sum(case when line.code in %s then line.total when line.code in %s then -abs(line.total) else 0 end) , 0) as "maximum"
FROM hr_payslip_line AS line
JOIN hr_payslip AS payslip
ON payslip.id = line.slip_id
WHERE line.employee_id = %s And
(line.code in %s Or line.code in %s)
AND line.date BETWEEN %s AND %s
AND payslip.id != %s
AND payslip.state IN ('draft', 'done', 'verify')
AND line.total != 0
group by line.slip_id
order by maximum desc
limit 1
"""
date_from, date_to = self.get_rule_dates(months_back, date_to)
query_arguments = (rule_code,rule_code_sub,self.employee_id.id or 0,
rule_code,
rule_code_sub,
date_from,
date_to,
self.id or 0)
total = 0
self.env.cr.execute(query, query_arguments)
try:
total = self.env.cr.dictfetchall()[0] or 0
except (IndexError, TypeError):
total = 0
print(total['maximum'])
return total['maximum']
class HRPayslip(models.Model):
......@@ -453,6 +508,8 @@ class HRPayslip(models.Model):
AND line.total != 0
"""
def _build_rule_total_sum_query(self):
""" Sum total of payslip lines"""
table = self._build_rule_table()
......@@ -463,6 +520,8 @@ class HRPayslip(models.Model):
table = self._build_rule_table()
return "SELECT COALESCE(MAX(line.total), 0) %s" % table
def _build_rule_month_query(self):
""" Get month and year of payslip lines"""
table = self._build_rule_table()
......@@ -534,11 +593,9 @@ class HRPayslip(models.Model):
total_max = float(self.query_rule_result(query, rule_code, months_back,
date_to, *args, **kwargs))
return total_max
def rule_month(self, rule_code, months_back=0,
date_to=False, *args, **kwargs):
"""
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment