Skip to content

Commit

Permalink
Removed unrequired fields, added a field for amount type on leave acc…
Browse files Browse the repository at this point in the history
…ruals and templates. Fixed views and translation
  • Loading branch information
dufresnedavid committed Dec 26, 2014
1 parent 5fa746f commit 61bf499
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 22 deletions.
10 changes: 9 additions & 1 deletion hr_leave_accruals/hr_leave_accrual.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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",
),
}
11 changes: 2 additions & 9 deletions hr_leave_accruals/hr_leave_accrual_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions hr_leave_accruals/hr_leave_accrual_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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',
Expand Down
12 changes: 6 additions & 6 deletions hr_leave_accruals/hr_payslip.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down
9 changes: 7 additions & 2 deletions hr_leave_accruals/i18n/fr.po
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
8 changes: 6 additions & 2 deletions hr_leave_accruals/i18n/hr_leave_accruals.pot
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
Expand Down Expand Up @@ -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 ""
Expand All @@ -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 ""
25 changes: 25 additions & 0 deletions hr_leave_accruals/test/hr_leave_accruals_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
1 change: 1 addition & 0 deletions hr_leave_accruals/view/hr_employee_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<field name="leave_accrual_ids">
<tree>
<field name="name"/>
<field name="amount_type"/>
<field name="total" string="Amount"/>
</tree>
</field>
Expand Down
1 change: 1 addition & 0 deletions hr_leave_accruals/view/hr_leave_accrual_template_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<form string="Leave Accrual Templates">
<field name="name"/>
<field name="code"/>
<field name="amount_type"/>
<label for="line_ids" string="Template Lines" colspan="4"/>
<field name="line_ids" nolabel="1" colspan="4">
<tree editable="top">
Expand Down
3 changes: 1 addition & 2 deletions hr_leave_accruals/view/hr_leave_accrual_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@
<form string="Leave Accrual">
<field name="template_id"/>
<field name="total" readonly="1"/>
<field name="amount_type" readonly="1"/>
<label for="line_ids" string="Leave Accrual Lines" colspan="4"/>
<field name="line_ids" nolabel="1" colspan="4">
<tree editable="top">
<field name="source" readonly="1"/>
<field name="payslip_id" readonly="1"/>
<field name="payslip_line_id" readonly="1"/>
<field name="salary_rule_id" readonly="1"/>
<field name="state" readonly="1"/>
<field name="amount" attrs="{'readonly': [('payslip_id', '!=', False)]}"/>
<field name="substract" attrs="{'readonly': [('payslip_id', '!=', False)]}"/>
<field name="date"
attrs="{
'readonly': [('payslip_id', '!=', False)],
Expand Down

0 comments on commit 61bf499

Please sign in to comment.