{FIX} : payslip print fix and days_count fix

This commit is contained in:
raman 2025-09-30 15:38:40 +05:30
parent 70eb7fb338
commit 3c4548156f
2 changed files with 67 additions and 21 deletions

View File

@ -1381,6 +1381,7 @@ class HrPayslip(models.Model):
def days_count(self):
days = self.worked_days_line_ids.filtered(lambda x:x.work_entry_type_id.code == 'OUT').number_of_days
joining_date = self.contract_id.date_start
if not joining_date or joining_date == self.date_from:
return 0
@ -1402,7 +1403,7 @@ class HrPayslip(models.Model):
weekend_days_count = weekend_count
else:
weekend_days_count = 0
return weekend_days_count
return weekend_days_count + days
def action_edit_payslip_lines(self):
self.ensure_one()
@ -1851,3 +1852,40 @@ class HrPayslip(models.Model):
if 'stats' in sections:
result['stats'] = self._get_dashboard_stats()
return result
def get_leave_balance(self):
employee = self.employee_id
if not employee:
return {'error': 'No employee linked to this user'}
leave_data = {}
leave_types = self.env['hr.leave.type'].search([
])
if not leave_types:
return []
for leave_type in leave_types:
allocations = self.env['hr.leave.allocation'].search([
('employee_id', '=', employee.id),
('holiday_status_id', '=', leave_type.id),
('state', '=', 'validate'),
])
taken_leaves = self.env['hr.leave'].search([
('employee_id', '=', employee.id),
('holiday_status_id', '=', leave_type.id),
('state', 'in', ['validate','validate1','confirm']),
])
total_allocated = sum(a.number_of_days for a in allocations)
total_taken = sum(l.number_of_days for l in taken_leaves)
remaining = total_allocated - total_taken
if remaining <= 0:
continue
leave_data[leave_type.name] = {
'name':leave_type.name,
'allocated': total_allocated,
'taken': total_taken,
'remaining': remaining,
}
return leave_data

View File

@ -44,20 +44,21 @@
<table style="width: 100%; border-collapse: collapse; font-size: 12px; margin-bottom: 10px;">
<tr>
<td style="border: 1px solid #ccc; padding: 6px;">
<u><b>Pay Summary</b></u><br/><br/>
<strong>Pay Period:</strong> <t style="padding: 6px;" t-esc="o.date_from"/> - <t t-esc="o.date_to"/><br/>
<t t-set="days" t-value="(o.date_to - o.date_from).days + 1"/>
<strong>Number of Days:</strong> <t style="padding: 6px;" t-esc="days"/> Days<br/>
<strong>Worked Days:</strong> <t style="padding: 6px;" t-esc="days"/> Days
</td>
<t t-set="timeoff_data_table" t-value="o._get_employee_timeoff_data()"/>
<td t-if="timeoff_data_table" style="border: 1px solid #ccc; padding: 6px;">
<div t-foreach="timeoff_data_table" t-as="timeoff_data">
<strong t-out="timeoff_data[0] + ':'"/>
<t t-out="timeoff_data[1].get('remaining_leaves')"/> /
<t t-out="timeoff_data[1].get('max_leaves')"/>
<t t-if="timeoff_data[1].get('request_unit') == 'hour'">Hours</t>
<t t-else="">Days</t>
<t t-set="leave_data" t-value="o.get_leave_balance()"/>
<td t-if="leave_data" style="border: 1px solid #ccc; padding: 6px;">
<p><u><b>Leave Balance</b></u>
<div t-foreach="leave_data.values()" t-as="data">
<strong t-out="data['name'] + ':'"/>
<t t-out="data['remaining']"/>
Days
</div>
</p>
</td>
</tr>
</table>
@ -76,12 +77,16 @@
<div t-foreach="o.line_ids.filtered(lambda l: l.appears_on_payslip and l.category_id.code in ['BASIC','SPA','ALW']and l.amount &gt; 0)" t-as="l">
<t t-esc="l.name"/><br/>
</div>
<br/>
<strong>Total Income</strong>
</td>
<td style="border: 1px solid #ccc; padding: 6px; text-align: right;">
<div t-foreach="o.line_ids.filtered(lambda l: l.appears_on_payslip and l.category_id.code in ['BASIC','SPA','ALW'] and l.amount &gt; 0)" t-as="l">
<t t-esc="l.amount"/><br/>
<t t-esc="'%.2f' % l.amount"/><br/>
<t t-set="income" t-value="income + l.amount"/>
</div>
<br/>
<strong><t t-esc="'%.2f' % income"/></strong>
</td>
<td style="border: 1px solid #ccc; padding: 6px;">
<t t-set="contribution" t-value="0"/>
@ -91,7 +96,7 @@
</td>
<td style="border: 1px solid #ccc; padding: 6px; text-align: right;">
<div t-foreach="o.line_ids.filtered(lambda l: l.appears_on_payslip and l.category_id.code in ['COMP','MA'] and l.amount &gt; 0)" t-as="l">
<t t-esc="l.amount"/><br/>
<t t-esc="'%.2f' % l.amount"/><br/>
<t t-set="contribution" t-value="contribution + l.amount"/>
</div>
</td>
@ -107,30 +112,33 @@
</div>
</td>
<td style="border: 1px solid #ccc; padding: 6px; text-align: right;">
<strong><t t-esc="contribution + income"/></strong><br/><br/><br/>
<strong><t t-esc="'%.2f' % (contribution + income)"/></strong><br/><br/><br/>
<div t-foreach="o.line_ids.filtered(lambda l: l.appears_on_payslip and l.category_id.code == 'DED')" t-as="l">
<t t-esc="l.amount"/><br/>
<t t-esc="'%.2f' % l.amount"/><br/>
<t t-set="ded" t-value="ded + l.amount"/>
</div>
</td>
</tr>
<tr>
<td style="border: 1px solid #ccc; padding: 6px;"><strong>Gross Salary</strong></td>
<td style="border: 1px solid #ccc; padding: 6px; text-align: right;"><strong><t t-esc="income"/></strong></td>
<td style="border: 1px solid #ccc; padding: 6px;"><strong>Total Deduction</strong></td>
<td style="border: 1px solid #ccc; padding: 6px; text-align: right;"><strong><t t-esc="ded"/></strong></td>
<td style="border: 1px solid #ccc; padding: 6px;" colspan="3"><strong>Gross Salary</strong></td>
<td style="border: 1px solid #ccc; padding: 6px; text-align: right;" colspan="1"><strong><t t-esc="'%.2f' % income"/></strong></td>
</tr>
<tr>
<td class="net-salary" colspan="3" style="border: 1px solid #ccc; padding: 6px;"><strong>Net Salary:</strong></td>
<td class="net-salary" colspan="1" style="border: 1px solid #ccc; padding: 6px; text-align: right;">
<t t-esc="(contribution + income) + ded"/>
<td style="border: 1px solid #ccc; padding: 6px;" colspan="3"><strong>Total Deduction</strong></td>
<td style="border: 1px solid #ccc; padding: 6px; text-align: right;" colspan="1"><strong><t t-esc="'%.2f' % ded"/></strong></td>
</tr>
<tr>
<td class="net-salary" colspan="3" style="border: 1px solid #ccc; padding: 6px;font-size: 14px;"><strong>Net Salary:</strong></td>
<td class="net-salary" colspan="1" style="border: 1px solid #ccc; padding: 6px; text-align: right;font-size: 14px;">
<strong><t t-esc="'%.2f' % (income + ded)"/></strong>
</td>
</tr>
</table>
<div class="to-pay" style="margin-top: 20px;">
<p t-if="o.net_wage &gt;= 0">
To pay <strong><span t-esc="(contribution + income) + ded"/></strong> (<span style="padding-right: 5px;" t-esc="o.env.company.currency_id.amount_to_text((contribution + income) + ded) "/> only) to <i><span t-field="o.employee_id.legal_name"/></i> - <b><span t-field="o.employee_id.bank_account_id.bank_id.name"/> Account : <span t-field="o.employee_id.bank_account_id.acc_number">XXXXXXXXXXXX</span></b>
To pay <strong><span t-esc="'%.2f' % (income + ded)"/></strong> (<span style="padding-right: 5px;" t-esc="o.env.company.currency_id.amount_to_text(income + ded)"/> only) to <i><span t-field="o.employee_id.legal_name"/></i> - <b><span t-field="o.employee_id.bank_account_id.bank_id.name"/> Account : <span t-field="o.employee_id.bank_account_id.acc_number">XXXXXXXXXXXX</span></b>
</p>