[ADD] hr_timesheet_work_entry: for Odoo 13

This commit is contained in:
Jared Kipe
2020-10-06 11:53:45 -07:00
parent 8f9ef7b259
commit a83cf2bfeb
11 changed files with 148 additions and 0 deletions

View File

@@ -0,0 +1,15 @@
from . import models
def ts_work_type_pre_init_hook(cr):
"""
This module installs a Work Entry Type with code "TS"
If you have undergone a migration (either for this module
or even your own Payslip Work Entry lines with code "TS")
then the uniqueness constraint will prevent this module
from installing.
"""
cr.execute("UPDATE hr_work_entry_type "
"SET code = 'TS-PRE-INSTALL' "
"WHERE code = 'TS';"
)

View File

@@ -0,0 +1,22 @@
{
'name': 'Timesheet Work Entry Type',
'description': 'Set work types on timesheet records.',
'version': '13.0.1.0.0',
'website': 'https://hibou.io/',
'author': 'Hibou Corp. <hello@hibou.io>',
'license': 'AGPL-3',
'category': 'Human Resources',
'depends': [
'hr_timesheet',
'hr_work_entry',
],
'data': [
'data/hr_timesheet_work_entry_data.xml',
'views/timesheet_views.xml',
'views/work_entry_views.xml',
],
'demo': [
'data/hr_timesheet_work_entry_demo.xml',
],
'pre_init_hook': 'ts_work_type_pre_init_hook',
}

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<record id="work_input_timesheet" model="hr.work.entry.type">
<field name="name">Timesheet</field>
<field name="code">TS</field>
<field name="allow_timesheet" eval="True"/>
</record>
</odoo>

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<record id="work_input_timesheet_internal" model="hr.work.entry.type">
<field name="name">Internal</field>
<field name="code">TS_INTERNAL</field>
<field name="allow_timesheet" eval="True"/>
</record>
</odoo>

View File

@@ -0,0 +1,2 @@
from . import timesheet
from . import work_entry

View File

@@ -0,0 +1,9 @@
from odoo import api, fields, models
class AccountAnalyticLine(models.Model):
_inherit = 'account.analytic.line'
work_type_id = fields.Many2one('hr.work.entry.type', string='Work Type',
default=lambda self: self.env.ref('hr_timesheet_work_entry.work_input_timesheet',
raise_if_not_found=False))

View File

@@ -0,0 +1,7 @@
from odoo import fields, models
class HrWorkEntryType(models.Model):
_inherit = 'hr.work.entry.type'
allow_timesheet = fields.Boolean(string='Allow on Timesheet')

View File

@@ -0,0 +1 @@
from . import test_timesheet_work_type

View File

@@ -0,0 +1,19 @@
from odoo.tests import common
class TestTimesheetWorkType(common.TransactionCase):
def setUp(self):
super().setUp()
self.employee = self.env.ref('hr.employee_hne')
self.project = self.env.ref('project.project_project_2')
self.default_work_type = self.env.ref('hr_timesheet_work_entry.work_input_timesheet')
def test_01_work_type(self):
timesheet = self.env['account.analytic.line'].create({
'name': '/',
'employee_id': self.employee.id,
'unit_amount': 1.0,
'project_id': self.project.id,
})
self.assertTrue(timesheet.work_type_id)
self.assertEqual(timesheet.work_type_id, self.default_work_type)

View File

@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<record id="hr_timesheet_line_tree_inherit" model="ir.ui.view">
<field name="name">account.analytic.line.tree.hr_timesheet.inherit</field>
<field name="model">account.analytic.line</field>
<field name="inherit_id" ref="hr_timesheet.hr_timesheet_line_tree"/>
<field name="arch" type="xml">
<xpath expr="//tree/field[@name='task_id']" position="after">
<field name="work_type_id"
domain="[('allow_timesheet', '=', True)]"
context="{'default_allow_timesheet': True}" />
</xpath>
</field>
</record>
<record id="hr_timesheet_line_form_inherit" model="ir.ui.view">
<field name="name">account.analytic.line.form.inherit</field>
<field name="model">account.analytic.line</field>
<field name="inherit_id" ref="hr_timesheet.hr_timesheet_line_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='task_id']" position="after">
<field name="work_type_id"
domain="[('allow_timesheet', '=', True)]"
context="{'default_allow_timesheet': True}" />
</xpath>
</field>
</record>
</odoo>

View File

@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<record id="hr_work_entry_type_view_form_inherit" model="ir.ui.view">
<field name="name">hr.work.type.view.form.inherit</field>
<field name="model">hr.work.entry.type</field>
<field name="inherit_id" ref="hr_work_entry.hr_work_entry_type_view_form"/>
<field name="arch" type="xml">
<xpath expr="//group/group" position="after">
<group name="timesheet" string="Timesheets">
<field name="allow_timesheet"/>
</group>
</xpath>
</field>
</record>
<menuitem
id="hr_work_entry_type_menu"
name="Work Entry Types"
parent="hr_timesheet.hr_timesheet_menu_configuration"
action="hr_work_entry.hr_work_entry_type_action"/>
</odoo>