Skip to content

Commit

Permalink
[16.0][ADD] hr_timesheet_name_customer:custom desc
Browse files Browse the repository at this point in the history
This module added new field Customer Description in list view
In this module in report pdf instead of Description you can see Customer
Description. This field can see only Timesheets:Administrator
  • Loading branch information
Andrey committed Feb 26, 2023
1 parent a9d4161 commit 3786e67
Show file tree
Hide file tree
Showing 15 changed files with 271 additions and 0 deletions.
1 change: 1 addition & 0 deletions hr_timesheet_name_customer/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

1 change: 1 addition & 0 deletions hr_timesheet_name_customer/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
17 changes: 17 additions & 0 deletions hr_timesheet_name_customer/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "Timesheet Description Customer",
"summary": "Add ‘Description Customer’ field for timesheets",
"version": "16.0.1.0.0",
"category": "Timesheet",
"website": "https://github.com/OCA/timesheet",
"maintainers": ["solo4games", "CetmixGitDrone"],
"author": "Odoo Community Association (OCA), Cetmix",
"license": "LGPL-3",
"application": False,
"installable": True,
"depends": ["hr_timesheet"],
"data": [
"views/hr_timesheet_name_customer_views.xml",
"report/name_customer_template.xml",
],
}
1 change: 1 addition & 0 deletions hr_timesheet_name_customer/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import hr_timesheet_name_customer
15 changes: 15 additions & 0 deletions hr_timesheet_name_customer/models/hr_timesheet_name_customer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from odoo import api, fields, models


class NameCustomer(models.Model):
_inherit = "account.analytic.line"

name_customer = fields.Char(string="Customer Description")
"""override create method, initialize name_customer"""

@api.model_create_multi
def create(self, vals_list):
for vals in vals_list:
if not vals.get("name_customer"):
vals["name_customer"] = vals["name"]
return super(NameCustomer, self).create(vals_list)
7 changes: 7 additions & 0 deletions hr_timesheet_name_customer/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
This module adds additional field "Description Customer" which is used for customer timesheet reports.
This might be useful if you need to translate original timesheet description or add some additional information into it while leaving original description intact.
This field is visible only for "Timesheets: Administrator" group.

By default this field will be populated from the "Description" field of the timesheet.

New report "Timesheet Customer" is used to print timesheets with "Customer Description" instead of the "Description" field.
5 changes: 5 additions & 0 deletions hr_timesheet_name_customer/readme/HISTORY.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
16.0.1.0.0 (2023-02-26)
~~~~~~~~~~~~~~~~~~~~~~~

* [ADD] Initial release for Odoo 16.
(`#568 <https://github.com/OCA/timesheet/pull/568>`_)
5 changes: 5 additions & 0 deletions hr_timesheet_name_customer/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
To use this module you need to:

#. Modify "Description Customer" field value.
#. Select timesheets you want to print add choose "Timesheets Customer" report.
#. "Description" column values will be populated from the "Description Customer" field.
83 changes: 83 additions & 0 deletions hr_timesheet_name_customer/report/name_customer_template.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<template id="name_customer_table" inherit_id="hr_timesheet.timesheet_table">
<xpath
expr="//table[hasclass('table', 'table-sm')]/thead/tr/th[5]"
position="attributes"
>
<attribute name="t-if">not show_desc</attribute>
</xpath>

<xpath
expr="//table[hasclass('table', 'table-sm')]/thead/tr/th[5]"
position="after"
>
<th class="text-start align-middle" t-if="show_custom_desc">
<span>Description</span>
</th>
</xpath>

<xpath
expr="//table[hasclass('table', 'table-sm')]/tbody/tr[1]/td[5]"
position="attributes"
>
<attribute name="t-if">not show_desc</attribute>
</xpath>

<xpath
expr="//table[hasclass('table', 'table-sm')]/tbody/tr[1]/td[5]"
position="after"
>
<td t-if="show_custom_desc" class="align-middle">
<span t-field="line.name_customer" t-options="{'widget': 'text'}" />
</td>
</xpath>
</template>

<!--Create customer timesheet report-->
<template id="report_timesheet_custom">
<t t-call="web.html_container">
<t t-call="web.external_layout">
<t
t-set="company"
t-value="docs.project_id.company_id if len(docs.project_id) == 1 else docs.env.company"
/>
<t t-set="show_task" t-value="bool(docs.task_id)" />
<t t-set="show_project" t-value="len(docs.project_id) > 1" />
<t t-set="show_desc" t-value="True" />
<t t-set="show_custom_desc" t-value="True" />
<div class="page">
<div class="oe_structure" />
<div class="row mt8">
<div class="col-lg-12">
<h2>
<span>Timesheets
<t t-if="len(docs.project_id) == 1">
for the <t
t-out="docs.project_id.name"
/> Project
</t>
</span>
</h2>
</div>
</div>
<t t-set='lines' t-value='docs' />
<t t-call="hr_timesheet_name_customer.name_customer_table" />
<div class="oe_structure" />
</div>
</t>
</t>
</template>

<record id="timesheet_report_name_custom" model="ir.actions.report">
<field name="name">Timesheet Customer</field>
<field name="model">account.analytic.line</field>
<field name="report_type">qweb-pdf</field>
<field
name="report_name"
>hr_timesheet_name_customer.report_timesheet_custom</field>
<field name="report_file">report_timesheet_custom</field>
<field name="binding_model_id" ref="model_account_analytic_line" />
<field name="binding_type">report</field>
</record>
</odoo>
2 changes: 2 additions & 0 deletions hr_timesheet_name_customer/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import test_name_customer
from . import common
77 changes: 77 additions & 0 deletions hr_timesheet_name_customer/tests/common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
from odoo.tests.common import TransactionCase


class TestCommonNameCustomer(TransactionCase):
@classmethod
def setUpClass(cls):
super(TestCommonNameCustomer, cls).setUpClass()

# customer partner
cls.partner = cls.env["res.partner"].create(
{
"name": "Customer For Analytic Account",
"email": "customer@task.com",
"phone": "42",
}
)

cls.analytic_plan = cls.env["account.analytic.plan"].create(
{
"name": "Plan Test",
"company_id": False,
}
)
cls.analytic_account = cls.env["account.analytic.account"].create(
{
"name": "Analytic Account for Test Customer",
"partner_id": cls.partner.id,
"plan_id": cls.analytic_plan.id,
"code": "TEST",
}
)

# project and tasks
cls.project_customer = cls.env["project.project"].create(
{
"name": "Project X",
"allow_timesheets": True,
"partner_id": cls.partner.id,
"analytic_account_id": cls.analytic_account.id,
}
)
cls.task1 = cls.env["project.task"].create(
{
"name": "Task One",
"priority": "0",
"kanban_state": "normal",
"project_id": cls.project_customer.id,
"partner_id": cls.partner.id,
}
)
cls.task2 = cls.env["project.task"].create(
{
"name": "Task Two",
"priority": "1",
"kanban_state": "done",
"project_id": cls.project_customer.id,
}
)
# users
cls.user_employee = cls.env["res.users"].create(
{
"name": "User Employee",
"login": "user_employee",
"email": "useremployee@test.com",
"groups_id": [
(6, 0, [cls.env.ref("hr_timesheet.group_hr_timesheet_user").id])
],
}
)

# employees
cls.empl_employee = cls.env["hr.employee"].create(
{
"name": "User Empl Employee",
"user_id": cls.user_employee.id,
}
)
33 changes: 33 additions & 0 deletions hr_timesheet_name_customer/tests/test_name_customer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from .common import TestCommonNameCustomer


class TestTimesheet(TestCommonNameCustomer):
def test_custom_name(self):
"""Test when Customer Description set or not: check name and name_customer equality"""
Timesheet = self.env["account.analytic.line"]
timesheet1 = Timesheet.with_user(self.user_employee).create(
{
"project_id": self.project_customer.id,
"task_id": self.task1.id,
"name": "my first timesheet",
}
)
self.assertEqual(
timesheet1.name,
timesheet1.name_customer,
"Description and Custom Description should be the same",
)

timesheet2 = Timesheet.with_user(self.user_employee).create(
{
"project_id": self.project_customer.id,
"task_id": self.task2.id,
"name": "my second timesheet",
"name_customer": "my second timesheet with another description",
}
)
self.assertNotEqual(
timesheet2.name,
timesheet2.name_customer,
"Description and Custom Description should be different",
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="hr_timesheet_line_tree" model="ir.ui.view">
<field name="name">Name Customer</field>
<field name="model">account.analytic.line</field>
<field name="inherit_id" ref="hr_timesheet.hr_timesheet_line_tree" />
<field name="arch" type="xml">
<field name="name" position="after">
<field
name="name_customer"
optional="show"
groups="hr_timesheet.group_timesheet_manager"
/>
</field>
</field>
</record>
</odoo>
6 changes: 6 additions & 0 deletions setup/hr_timesheet_name_customer/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)

0 comments on commit 3786e67

Please sign in to comment.