From f29d9dfe2e6f5bb835574097f6be7f613eea3fe6 Mon Sep 17 00:00:00 2001 From: Yannick Tivisse Date: Thu, 29 Nov 2018 12:39:13 +0100 Subject: [PATCH] [IMP] hr_payroll: Put single payslips in a batch. When creating a payslip, if no batch is defined for it, put it automatically in a new batch. --- addons/hr_payroll/models/hr_payslip.py | 13 +++++++++++++ .../tests/test_hr_payroll_account.py | 1 + 2 files changed, 14 insertions(+) diff --git a/addons/hr_payroll/models/hr_payslip.py b/addons/hr_payroll/models/hr_payslip.py index af1750a19c9..bc088388cf6 100644 --- a/addons/hr_payroll/models/hr_payslip.py +++ b/addons/hr_payroll/models/hr_payslip.py @@ -112,6 +112,19 @@ class HrPayslip(models.Model): 'context': {} } + @api.model + def create(self, vals): + res = super(HrPayslip, self).create(vals) + if not res.payslip_run_id: + self.env['hr.payslip.run'].create({ + 'name': res.name, + 'date_start': res.date_from, + 'date_end': res.date_to, + 'slip_ids': [(4, res.id)], + 'state': 'close', + }) + return res + @api.multi def unlink(self): if any(self.filtered(lambda payslip: payslip.state not in ('draft', 'cancel'))): diff --git a/addons/hr_payroll_account/tests/test_hr_payroll_account.py b/addons/hr_payroll_account/tests/test_hr_payroll_account.py index 202a42db0fc..2d4be4829ba 100644 --- a/addons/hr_payroll_account/tests/test_hr_payroll_account.py +++ b/addons/hr_payroll_account/tests/test_hr_payroll_account.py @@ -74,6 +74,7 @@ class TestHrPayrollAccount(common.TransactionCase): self.hr_payslip = self.env['hr.payslip'].create({ 'employee_id': self.hr_employee_john.id, 'journal_id': self.ref('hr_payroll_account.expenses_journal'), + 'name': 'Test Payslip', }) def test_00_hr_payslip(self):