IMP hr_payroll_slip_ytd Add totals for Quantity and Amount for better YTD reporting.

This commit is contained in:
Jared Kipe
2020-02-19 12:04:03 -08:00
committed by Cedric Collins
parent caff2a713a
commit f5f73f352c
3 changed files with 19 additions and 5 deletions

View File

@@ -1,7 +1,7 @@
{
'name': 'Payroll Report Year to Date',
'author': 'Hibou Corp. <hello@hibou.io>',
'version': '12.0.1.0.0',
'version': '12.0.1.1.0',
'category': 'Human Resources',
'sequence': 95,
'summary': 'Show YTD computations on Payslip Report',

View File

@@ -9,11 +9,20 @@ class Payslip(models.Model):
from_date = str(self.date_to.year) + '-01-01'
state_allowed = ('done', 'verify') if not allow_draft else ('done', 'verify', 'draft')
self.env.cr.execute("""
SELECT sum(total) as sum
SELECT sum(total) as total,
sum(quantity) as quantity,
sum(amount) as amount
FROM hr_payslip as hp
JOIN hr_payslip_line as pi ON hp.id = pi.slip_id
WHERE hp.employee_id = %s
AND hp.state in %s
AND hp.date_to >= %s AND hp.date_to <= %s AND pi.code = %s""",
(self.employee_id.id, state_allowed, from_date, to_date, code))
return self.env.cr.fetchone()[0] or 0.0
res = self.env.cr.dictfetchone()
if res:
# Can return dictionary with NULL aka Nones
for key in res:
res[key] = res[key] or 0.0
else:
res = {'total': 0.0, 'quantity': 0.0, 'amount': 0.0}
return res

View File

@@ -3,12 +3,17 @@
<template id="report_payslip_inherit" name="Payslip YTD" inherit_id="hr_payroll.report_payslip">
<!-- Add YTD to the table head-->
<xpath expr="//table[2]/thead/tr//th[last()]" position="after">
<th>YTD</th>
<th>YTD Quantity</th>
<th>YTD Amount</th>
<th>YTD Total</th>
</xpath>
<!-- Add YTD table data-->
<xpath expr="//table[2]/tbody//td[last()]" position="after">
<td><span t-esc="o.ytd(line.code, allow_draft=True)" t-options="{&quot;widget&quot;: &quot;monetary&quot;, &quot;display_currency&quot;: o.company_id.currency_id}"/></td>
<t t-set="ytd" t-value="o.ytd(line.code, allow_draft=True)"/>
<td><span t-esc="ytd.get('quantity', 0.0)"/></td>
<td><span t-esc="ytd.get('amount', 0.0)" t-options="{&quot;widget&quot;: &quot;monetary&quot;, &quot;display_currency&quot;: o.company_id.currency_id}"/></td>
<td><span t-esc="ytd.get('total', 0.0)" t-options="{&quot;widget&quot;: &quot;monetary&quot;, &quot;display_currency&quot;: o.company_id.currency_id}"/></td>
</xpath>
</template>
</odoo>