Commit 10200ce6 authored by Santiago Apel's avatar Santiago Apel 💬
Browse files

Merge branch 'rule_total_max' into '12.0-stage'

Rule total max

See merge request !24
parents 9f220269 e20ea402
......@@ -440,12 +440,13 @@ class HRPayslip(models.Model):
return date_from, date_to
def _build_rule_table(self):
return """
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)
AND line.code in %s
AND line.date BETWEEN %s AND %s
AND payslip.id != %s
AND payslip.state IN ('draft', 'done', 'verify')
......@@ -500,7 +501,7 @@ class HRPayslip(models.Model):
date_from, date_to = self.get_rule_dates(int(months_back), date_to)
query_arguments = self._get_query_rule_arguments(
rule_code, date_from, date_to, *args, **kwargs
(rule_code, ), date_from, date_to, *args, **kwargs
)
self.env.cr.execute(query, query_arguments)
try:
......@@ -527,9 +528,20 @@ class HRPayslip(models.Model):
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 = self._build_rule_total_max_query()
total_max = float(self.query_rule_result(query, rule_code, months_back,
if type(rule_code) == str:
query = self._build_rule_total_max_query()
total_max = float(self.query_rule_result(query, rule_code, months_back,
date_to, *args, **kwargs))
else:
aux_list = []
for rulecode in rule_code:
query = self._build_rule_total_max_query()
total_max = float(self.query_rule_result(query, rulecode, months_back,
date_to, *args, **kwargs))
aux_list.append(total_max)
total_max = max(aux_list)
return total_max
def rule_month(self, rule_code, months_back=0,
......
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