diff --git a/hr_leave_accruals/hr_leave_accrual.py b/hr_leave_accruals/hr_leave_accrual.py
index 027c8cc19395..86c5eb28903c 100644
--- a/hr_leave_accruals/hr_leave_accrual.py
+++ b/hr_leave_accruals/hr_leave_accrual.py
@@ -20,6 +20,7 @@
##############################################################################
from openerp.osv import orm, fields
+from .hr_leave_accrual_template import get_amount_types
class hr_leave_accrual(orm.Model):
@@ -74,7 +75,7 @@ def _sum_lines(
lines = approved_lines[accrual_id]
for line in lines:
- if line.substract:
+ if line.is_refund:
total -= line.amount
else:
total += line.amount
@@ -118,4 +119,11 @@ def _sum_lines(
type="float",
string='Total',
),
+ 'amount_type': fields.related(
+ 'template_id',
+ 'amount_type',
+ type="selection",
+ selection=get_amount_types,
+ string="Amount Type",
+ ),
}
diff --git a/hr_leave_accruals/hr_leave_accrual_line.py b/hr_leave_accruals/hr_leave_accrual_line.py
index 0e07ebc63c5e..5dab6fb06786 100644
--- a/hr_leave_accruals/hr_leave_accrual_line.py
+++ b/hr_leave_accruals/hr_leave_accrual_line.py
@@ -45,9 +45,6 @@ class hr_leave_accrual_line(orm.Model):
'Amount',
required=True,
),
- 'substract': fields.boolean(
- 'Substract Amount'
- ),
'source': fields.selection(
[
('payslip', 'Payslip Line'),
@@ -75,12 +72,8 @@ class hr_leave_accrual_line(orm.Model):
type="char",
string="State"
),
- 'salary_rule_id': fields.related(
- 'payslip_line_id',
- 'salary_rule_id',
- type="many2one",
- relation='hr.salary.rule',
- string="Salary Rule",
+ 'is_refund': fields.boolean(
+ 'Is Refund',
),
# Fields required when the line is entered manually
diff --git a/hr_leave_accruals/hr_leave_accrual_template.py b/hr_leave_accruals/hr_leave_accrual_template.py
index f447ef493a5b..8cb6da8436c0 100644
--- a/hr_leave_accruals/hr_leave_accrual_template.py
+++ b/hr_leave_accruals/hr_leave_accrual_template.py
@@ -20,6 +20,14 @@
##############################################################################
from openerp.osv import orm, fields
+from openerp.tools.translate import _
+
+
+def get_amount_types(self, cr, uid, context=None):
+ return [
+ ('cash', _('Cash')),
+ ('hours', _('Hours')),
+ ]
class hr_leave_accrual_template(orm.Model):
@@ -41,6 +49,10 @@ class hr_leave_accrual_template(orm.Model):
'Template Code',
required=True,
),
+ 'amount_type': fields.selection(
+ get_amount_types,
+ string="Amount Type",
+ ),
'line_ids': fields.one2many(
'hr.leave.accrual.template.line',
'template_id',
diff --git a/hr_leave_accruals/hr_payslip.py b/hr_leave_accruals/hr_payslip.py
index 2368e23bfe46..dee4d81868cc 100644
--- a/hr_leave_accruals/hr_payslip.py
+++ b/hr_leave_accruals/hr_payslip.py
@@ -69,10 +69,6 @@ def compute_leave_accrual_lines(self, cr, uid, ids, context=None):
if line.salary_rule_id.id in required_rules
}
- # If the payslip is a refund, all amounts need to be computed
- # by the reverse way.
- is_refund = payslip.credit_note and -1 or 1
-
# Create a list of new register line records
accrual_lines = []
for accrual in accruals:
@@ -89,14 +85,18 @@ def compute_leave_accrual_lines(self, cr, uid, ids, context=None):
):
# Get the payslip line related to the template line
payslip_line = payslip_line_dict[salary_rule_id]
+
+ amount = line.substract and payslip_line.amount * -1 \
+ or payslip_line.amount
+
if payslip_line.amount != 0:
accrual_lines.append((0, 0, {
'source': 'payslip',
'payslip_id': payslip.id,
'payslip_line_id': payslip_line.id,
- 'amount': payslip_line.amount * is_refund,
+ 'amount': amount,
'accrual_id': accrual.id,
- 'substract': line.substract,
+ 'is_refund': payslip.credit_note,
}))
# Write the resulting records
diff --git a/hr_leave_accruals/i18n/fr.po b/hr_leave_accruals/i18n/fr.po
index effbb83d01c9..ed72125ed157 100644
--- a/hr_leave_accruals/i18n/fr.po
+++ b/hr_leave_accruals/i18n/fr.po
@@ -76,10 +76,9 @@ msgstr "Date"
#. module: hr_leave_accruals
#: model:ir.model,name:hr_leave_accruals.model_hr_leave_accrual_line
msgid "Leave Accrual Line"
-msgstr "Ligne de template de banque de temps"
+msgstr "Ligne de banque de temps"
#. module: hr_leave_accruals
-#: field:hr.leave.accrual.line,substract:0
#: field:hr.leave.accrual.template.line,substract:0
msgid "Substract Amount"
msgstr "Soustraire le montant"
@@ -176,3 +175,9 @@ msgstr "Règle de salaire"
#: selection:hr.leave.accrual.line,category:0
msgid "Allowance taken by the employee"
msgstr "Allocation consommée par un employé"
+
+#. module: hr_leave_accruals
+#: field:hr.leave.accrual,amount_type:0
+#: field:hr.leave.accrual.template,amount_type:0
+msgid "Amount Type"
+msgstr "Type de montant"
diff --git a/hr_leave_accruals/i18n/hr_leave_accruals.pot b/hr_leave_accruals/i18n/hr_leave_accruals.pot
index a3a40af4b6db..4aac9809680b 100644
--- a/hr_leave_accruals/i18n/hr_leave_accruals.pot
+++ b/hr_leave_accruals/i18n/hr_leave_accruals.pot
@@ -79,7 +79,6 @@ msgid "Leave Accrual Line"
msgstr ""
#. module: hr_leave_accruals
-#: field:hr.leave.accrual.line,substract:0
#: field:hr.leave.accrual.template.line,substract:0
msgid "Substract Amount"
msgstr ""
@@ -167,7 +166,6 @@ msgid "Template Lines"
msgstr ""
#. module: hr_leave_accruals
-#: field:hr.leave.accrual.line,salary_rule_id:0
#: field:hr.leave.accrual.template.line,salary_rule_id:0
msgid "Salary Rule"
msgstr ""
@@ -176,3 +174,9 @@ msgstr ""
#: selection:hr.leave.accrual.line,category:0
msgid "Allowance taken by the employee"
msgstr ""
+
+#. module: hr_leave_accruals
+#: field:hr.leave.accrual,amount_type:0
+#: field:hr.leave.accrual.template,amount_type:0
+msgid "Amount Type"
+msgstr ""
diff --git a/hr_leave_accruals/test/hr_leave_accruals_test.yml b/hr_leave_accruals/test/hr_leave_accruals_test.yml
index 8c14b6a0e429..5a2215b19541 100644
--- a/hr_leave_accruals/test/hr_leave_accruals_test.yml
+++ b/hr_leave_accruals/test/hr_leave_accruals_test.yml
@@ -134,3 +134,28 @@
# the total in leave accrual must be 400
# 500 added - 300 taken + 500 added - 300 taken
assert(leave_accrual.total == 400)
+
+-
+ Create a refund payslip
+-
+ !record {model: hr.payslip, id: payslip_3}:
+ employee_id: employee_1
+ contract_id: contract_1
+ date_from: '2014-02-01'
+ date_to: '2014-02-28'
+ struct_id: structure_1
+ credit_note: True
+-
+ Compute the payslip
+-
+ !python {model: hr.payslip}: |
+ self.compute_sheet(cr, uid, [ref('payslip_3')])
+ self.write(cr, uid, [ref('payslip_3')], {'state': 'done'})
+-
+ Check if leave accrual lines were generated
+-
+ !python {model: hr.leave.accrual}: |
+ leave_accrual = self.browse(cr, uid, ref('leave_accrual_1'))
+ # the total in leave accrual must be 200 (400 - 200)
+ # because the last payslip is refund
+ assert(leave_accrual.total == 200)
diff --git a/hr_leave_accruals/view/hr_employee_view.xml b/hr_leave_accruals/view/hr_employee_view.xml
index a7a6b9f7d462..bcf8e08fc6f4 100644
--- a/hr_leave_accruals/view/hr_employee_view.xml
+++ b/hr_leave_accruals/view/hr_employee_view.xml
@@ -11,6 +11,7 @@