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
OCA-git-bot authored and Andrey committed Jun 28, 2023
1 parent 5f8d1e8 commit 10ddf55
Show file tree
Hide file tree
Showing 19 changed files with 289 additions and 6 deletions.
3 changes: 2 additions & 1 deletion .copier-answers.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# Do NOT update manually; changes here will be overwritten by Copier
_commit: v1.11.0
_commit: v1.14.1
_src_path: gh:oca/oca-addons-repo-template
ci: GitHub
dependency_installation_mode: PIP
generate_requirements_txt: true
github_check_license: true
github_ci_extra_env: {}
github_enable_codecov: true
github_enable_makepot: true
github_enable_stale_action: true
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:

jobs:
pre-commit:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
fi
done
test:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
container: ${{ matrix.container }}
name: ${{ matrix.name }}
strategy:
Expand Down
11 changes: 8 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ repos:
entry: found forbidden files; remove them
language: fail
files: "\\.rej$"
- id: en-po-files
name: en.po files cannot exist
entry: found a en.po file
language: fail
files: '[a-zA-Z0-9_]*/i18n/en\.po$'
- repo: https://github.com/oca/maintainer-tools
rev: 4cd2b852214dead80822e93e6749b16f2785b2fe
hooks:
Expand Down Expand Up @@ -96,15 +101,15 @@ repos:
- id: pyupgrade
args: ["--keep-percent-format"]
- repo: https://github.com/PyCQA/isort
rev: 5.10.1
rev: 5.12.0
hooks:
- id: isort
name: isort except __init__.py
args:
- --settings=.
exclude: /__init__\.py$
- repo: https://github.com/acsone/setuptools-odoo
rev: 3.1.5
rev: 3.1.8
hooks:
- id: setuptools-odoo-make-default
- id: setuptools-odoo-get-requirements
Expand All @@ -113,7 +118,7 @@ repos:
- requirements.txt
- --header
- "# generated from manifests external_dependencies"
- repo: https://gitlab.com/PyCQA/flake8
- repo: https://github.com/PyCQA/flake8
rev: 3.9.2
hooks:
- id: flake8
Expand Down
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
17 changes: 17 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,17 @@
# Copyright 2023-nowdays Cetmix OU (https://cetmix.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
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
79 changes: 79 additions & 0 deletions hr_timesheet_name_customer/tests/common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Copyright 2023-nowdays Cetmix OU (https://cetmix.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
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,
}
)
35 changes: 35 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,35 @@
# Copyright 2023-nowdays Cetmix OU (https://cetmix.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
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 10ddf55

Please sign in to comment.