Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[17.0][MIG] l10n_th_tier_department #482

Open
wants to merge 6 commits into
base: 17.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 116 additions & 0 deletions l10n_th_tier_department/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
=========================================
Thai Localization - Tier Department Level
=========================================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:2d56f0be93d906b076c06691060704b466c222b41c1606c870129e5430a7e8cd
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png
:target: https://odoo-community.org/page/development-status
:alt: Alpha
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fl10n--thailand-lightgray.png?logo=github
:target: https://github.com/OCA/l10n-thailand/tree/17.0/l10n_th_tier_department
:alt: OCA/l10n-thailand
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/l10n-thailand-17-0/l10n-thailand-17-0-l10n_th_tier_department
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/l10n-thailand&target_branch=17.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module adds an additional level of hierarchical validation in the
department for approvals when there are more than one.

.. IMPORTANT::
This is an alpha version, the data model and design can change at any time without warning.
Only for development or testing purpose, do not use in production.
`More details on development status <https://odoo-community.org/page/development-status>`_

**Table of contents**

.. contents::
:local:

Usage
=====

To use this module, call the find_reviewer_level function on the
hr.department object, and provide the level attribute as an argument.

This function retrieves reviewers from the specified department and
returns a user.

For example, Department AA has 3 Approvers:

- User A
- User B
- User C

and you need to find the reviewer at level 1, you can use the following
code:

.. code:: python

rec.employee_id.department_id.find_reviewer_level(level=1)

The result will be User A.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/l10n-thailand/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/l10n-thailand/issues/new?body=module:%20l10n_th_tier_department%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
-------

* Ecosoft

Contributors
------------

- `Ecosoft <http://ecosoft.co.th>`__:

- Pimolnat Suntian <[email protected]>

Maintainers
-----------

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

.. |maintainer-ps-tubtim| image:: https://github.com/ps-tubtim.png?size=40px
:target: https://github.com/ps-tubtim
:alt: ps-tubtim

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-ps-tubtim|

This module is part of the `OCA/l10n-thailand <https://github.com/OCA/l10n-thailand/tree/17.0/l10n_th_tier_department>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
3 changes: 3 additions & 0 deletions l10n_th_tier_department/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from . import models
22 changes: 22 additions & 0 deletions l10n_th_tier_department/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright 2023 Ecosoft Co., Ltd. (http://ecosoft.co.th)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
"name": "Thai Localization - Tier Department Level",
"version": "17.0.1.0.0",
"author": "Ecosoft, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/l10n-thailand",
"license": "AGPL-3",
"category": "Localization / Tools",
"depends": ["base_tier_validation_formula", "hr"],
"data": [
"security/tier_validation_department_security.xml",
"security/ir.model.access.csv",
"templates/tier_validation_templates.xml",
"views/hr_department_views.xml",
"views/tier_level_views.xml",
],
"installable": True,
"development_status": "Alpha",
"maintainers": ["ps-tubtim"],
}
120 changes: 120 additions & 0 deletions l10n_th_tier_department/i18n/l10n_th_tier_department.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * l10n_th_tier_department
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: l10n_th_tier_department
#: model:res.groups,name:l10n_th_tier_department.group_allow_restart_validation
msgid "Allow Restart Validation"
msgstr ""

#. module: l10n_th_tier_department
#: model:ir.model.fields,field_description:l10n_th_tier_department.field_hr_department__tier_level_ids
#: model_terms:ir.ui.view,arch_db:l10n_th_tier_department.view_department_form
msgid "Approval Level"
msgstr ""

#. module: l10n_th_tier_department
#: model:ir.model.fields,field_description:l10n_th_tier_department.field_tier_level__user_id
msgid "Approver"
msgstr ""

#. module: l10n_th_tier_department
#: model:ir.model.fields,field_description:l10n_th_tier_department.field_tier_level__company_id
msgid "Company"
msgstr ""

#. module: l10n_th_tier_department
#: model:ir.model.fields,help:l10n_th_tier_department.field_tier_level__company_id
msgid "Company related to this journal"
msgstr ""

#. module: l10n_th_tier_department
#: model_terms:ir.actions.act_window,help:l10n_th_tier_department.action_tier_level
msgid "Create a new tier level"
msgstr ""

#. module: l10n_th_tier_department
#: model:ir.model.fields,field_description:l10n_th_tier_department.field_tier_level__create_uid
msgid "Created by"
msgstr ""

#. module: l10n_th_tier_department
#: model:ir.model.fields,field_description:l10n_th_tier_department.field_tier_level__create_date
msgid "Created on"
msgstr ""

#. module: l10n_th_tier_department
#: model:ir.model,name:l10n_th_tier_department.model_hr_department
#: model:ir.model.fields,field_description:l10n_th_tier_department.field_tier_level__department_id
msgid "Department"
msgstr ""

#. module: l10n_th_tier_department
#: model:ir.model.fields,field_description:l10n_th_tier_department.field_tier_level__name
msgid "Description"
msgstr ""

#. module: l10n_th_tier_department
#: model:ir.model.fields,field_description:l10n_th_tier_department.field_tier_level__display_name
msgid "Display Name"
msgstr ""

#. module: l10n_th_tier_department
#: model:ir.model.fields,field_description:l10n_th_tier_department.field_tier_level__id
msgid "ID"
msgstr ""

#. module: l10n_th_tier_department
#: model:ir.model.fields,field_description:l10n_th_tier_department.field_tier_level____last_update
msgid "Last Modified on"
msgstr ""

#. module: l10n_th_tier_department
#: model:ir.model.fields,field_description:l10n_th_tier_department.field_tier_level__write_uid
msgid "Last Updated by"
msgstr ""

#. module: l10n_th_tier_department
#: model:ir.model.fields,field_description:l10n_th_tier_department.field_tier_level__write_date
msgid "Last Updated on"
msgstr ""

#. module: l10n_th_tier_department
#: model:ir.model.fields,field_description:l10n_th_tier_department.field_tier_level__level
msgid "Level"
msgstr ""

#. module: l10n_th_tier_department
#: model:res.groups,name:l10n_th_tier_department.group_manage_tier_level
msgid "Manage Approval Levels"
msgstr ""

#. module: l10n_th_tier_department
#: model:ir.model.fields,field_description:l10n_th_tier_department.field_tier_level__sequence
msgid "Sequence"
msgstr ""

#. module: l10n_th_tier_department
#: model_terms:ir.ui.view,arch_db:l10n_th_tier_department.tier_validation_buttons
msgid ""
"This action will restart all tier validation it cannot be undone. Are you "
"sure to continue?"
msgstr ""

#. module: l10n_th_tier_department
#: model:ir.actions.act_window,name:l10n_th_tier_department.action_tier_level
#: model:ir.model,name:l10n_th_tier_department.model_tier_level
#: model_terms:ir.ui.view,arch_db:l10n_th_tier_department.view_tier_level_form
msgid "Tier Level"
msgstr ""
4 changes: 4 additions & 0 deletions l10n_th_tier_department/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from . import hr_department
from . import tier_level
26 changes: 26 additions & 0 deletions l10n_th_tier_department/models/hr_department.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright 2023 Ecosoft Co., Ltd (http://ecosoft.co.th/)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from odoo import fields, models


class Department(models.Model):
_inherit = "hr.department"

tier_level_ids = fields.One2many(
string="Approval Level",
comodel_name="tier.level",
inverse_name="department_id",
)

def find_reviewer_level(self, level=0):
self.ensure_one()
num_level = len(self.tier_level_ids)
if not (level and num_level):
return self.env.user
tier_level_ids = self.tier_level_ids.sorted(key=lambda t: t.level)
return (
tier_level_ids[level - 1].user_id
if level <= num_level
else tier_level_ids[-1].user_id
)
44 changes: 44 additions & 0 deletions l10n_th_tier_department/models/tier_level.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Copyright 2023 Ecosoft Co., Ltd (http://ecosoft.co.th/)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from odoo import api, fields, models


class TierLevel(models.Model):
_name = "tier.level"
_description = "Tier Level"

department_id = fields.Many2one(
comodel_name="hr.department",
string="Department",
)
sequence = fields.Integer(default=10)
level = fields.Integer(compute="_compute_level")
user_id = fields.Many2one(
comodel_name="res.users",
string="Approver",
required=True,
)
name = fields.Char(string="Description")
company_id = fields.Many2one(
comodel_name="res.company",
string="Company",
required=True,
readonly=True,
index=True,
default=lambda self: self.env.company,
help="Company related to this journal",
)

@api.depends("sequence")
def _compute_level(self):
TierLevel = self.env["tier.level"]
for rec in self:
tier_level_ids = TierLevel.search(
[("department_id", "=", rec.department_id.id)], order="sequence"
).ids
rec.level = (
tier_level_ids.index(rec._origin.id) + 1
if rec._origin.id in tier_level_ids
else 0
)
3 changes: 3 additions & 0 deletions l10n_th_tier_department/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
2 changes: 2 additions & 0 deletions l10n_th_tier_department/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- [Ecosoft](http://ecosoft.co.th):
- Pimolnat Suntian \<<[email protected]>\>
2 changes: 2 additions & 0 deletions l10n_th_tier_department/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This module adds an additional level of hierarchical validation in the
department for approvals when there are more than one.
20 changes: 20 additions & 0 deletions l10n_th_tier_department/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
To use this module, call the find_reviewer_level function on the
hr.department object, and provide the level attribute as an argument.

This function retrieves reviewers from the specified department and
returns a user.

For example, Department AA has 3 Approvers:

- User A
- User B
- User C

and you need to find the reviewer at level 1, you can use the following
code:

``` python
rec.employee_id.department_id.find_reviewer_level(level=1)
```

The result will be User A.
3 changes: 3 additions & 0 deletions l10n_th_tier_department/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_tier_level_user,tier.level user,model_tier_level,base.group_user,1,0,0,0
access_tier_level,tier.level manage,model_tier_level,l10n_th_tier_department.group_manage_tier_level,1,1,1,1
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<odoo noupdate="1">

<record id="group_manage_tier_level" model="res.groups">
<field name="name">Manage Approval Levels</field>
<field name="category_id" ref="base.module_category_hidden" />
</record>

<record id="group_allow_restart_validation" model="res.groups">
<field name="name">Allow Restart Validation</field>
<field name="category_id" ref="base.module_category_hidden" />
</record>

<record id="base.group_system" model="res.groups">
<field
name="implied_ids"
eval="[(4, ref('l10n_th_tier_department.group_manage_tier_level')), (4, ref('l10n_th_tier_department.group_allow_restart_validation'))]"
/>
</record>

</odoo>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading