Skip to content

Commit

Permalink
[8.0.1.1.0][hr_timesheet_computation_overtime]
Browse files Browse the repository at this point in the history
* Add button and context action to link overtime with timesheet
  • Loading branch information
mikevhe18 authored and andhit-r committed Feb 8, 2020
1 parent 37186e9 commit bd550ad
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 6 deletions.
3 changes: 2 additions & 1 deletion hr_timesheet_computation_overtime/__openerp__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Timesheet Computation Integration With Overtime",
"version": "8.0.1.0.0",
"version": "8.0.1.1.0",
"category": "Human Resource",
"website": "https://opensynergy-indonesia.com",
"author": "OpenSynergy Indonesia",
Expand All @@ -14,6 +14,7 @@
"hr_attendance_overtime_request",
],
"data": [
"data/ir_actions_server_data.xml",
"views/hr_timesheet_sheet_views.xml",
"views/hr_overtime_request_views.xml",
],
Expand Down
26 changes: 26 additions & 0 deletions hr_timesheet_computation_overtime/data/ir_actions_server_data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>

<record id="hr_overtime_request_compute_timesheet_action" model="ir.actions.server">
<field name="name">Link to Timesheet</field>
<field name="type">ir.actions.server</field>
<field name="state">code</field>
<field name="model_id" ref="hr_attendance_overtime_request.model_hr_overtime_request"/>
<field name="code">active_ids = env.context.get("active_ids", False)
if active_ids:
for document in object.browse(active_ids):
if document.state in ["draft", "confirm"]:
document.button_link_to_timesheet()
</field>
</record>

<record id="hr_overtime_request_compute_timesheet_value" model="ir.values">
<field name="name">Link to Timesheet</field>
<field name="model">hr.overtime_request</field>
<field name="key2">client_action_multi</field>
<field name="value" eval="'ir.actions.server,' + str(ref('hr_overtime_request_compute_timesheet_action'))" />
</record>

</data>
</openerp>
20 changes: 15 additions & 5 deletions hr_timesheet_computation_overtime/models/hr_overtime_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,23 @@
class HrOvertimeRequest(models.Model):
_inherit = "hr.overtime_request"

@api.multi
def _prepare_criteria_timesheet(self):
self.ensure_one()
criteria = [
("employee_id", "=", self.employee_id.id),
("date_from", "<=", self.date_start),
("date_to", ">=", self.date_end),
]
return criteria

@api.multi
@api.depends(
"employee_id", "date_start", "date_end")
def _compute_sheet(self):
obj_sheet = self.env["hr_timesheet_sheet.sheet"]
for overtime in self:
criteria = [
("employee_id", "=", overtime.employee_id.id),
("date_from", "<=", overtime.date_start),
("date_to", ">=", overtime.date_end),
]
criteria = overtime._prepare_criteria_timesheet()
sheets = obj_sheet.search(criteria, limit=1)
overtime.sheet_id = sheets[0].id if len(sheets) > 0 else False

Expand All @@ -28,3 +34,7 @@ def _compute_sheet(self):
compute="_compute_sheet",
store=True,
)

@api.multi
def button_link_to_timesheet(self):
return self._compute_sheet()
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
<xpath expr="//field[@name='employee_id']" position="after">
<field name="sheet_id" groups="base.group_system"/>
</xpath>
<xpath expr="//field[@name='state']" position="before">
<button name="button_link_to_timesheet" string="Link to Timesheet" type="object" attrs="{'invisible':['|',('state','not in',['draft','confirm']),('sheet_id','!=',False)]}"/>
</xpath>
</data>
</field>
</record>
Expand Down

0 comments on commit bd550ad

Please sign in to comment.