diff --git a/hr_expense_employee_analytic_default/README.rst b/hr_expense_employee_analytic_default/README.rst new file mode 100644 index 000000000..304ab6f29 --- /dev/null +++ b/hr_expense_employee_analytic_default/README.rst @@ -0,0 +1,112 @@ +================================= +Expense Employee Analytic Default +================================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:ab96c55a5f8cea8244c3c3c29d53e6333b826592914af9d503103f34cb3cfb1b + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |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%2Fhr--expense-lightgray.png?logo=github + :target: https://github.com/OCA/hr-expense/tree/18.0/hr_expense_employee_analytic_default + :alt: OCA/hr-expense +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/hr-expense-18-0/hr-expense-18-0-hr_expense_employee_analytic_default + :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/hr-expense&target_branch=18.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allows to create Analytic Distribution Models for employees +to be applied to expenses. + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +To configure this module, you need to: + +1. Enable the “Analytic Accounting” permission on the user +2. Go to an employee (or create a new one) and set a work address +3. Go to *Invocing > Configuration > Analytic Accounting \|> Analytic + Distribution Models* and create a record that has as partner the + employee's work address. + +Usage +===== + +To use this module, you need to: + +1. Go to *Expenses* and create a new one. +2. The analytical distribution will be set according to the analytic + distribution model. +3. When changing the employee, the analytical distribution will be + updated. + +Bug Tracker +=========== + +Bugs are tracked on `GitHub 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 `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* Tecnativa + +Contributors +------------ + +- `Tecnativa `__: + + - Víctor Martínez + - Pedro M. Baeza + +- ``Heliconia Solutions Pvt. Ltd. ``\ \_ + +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-victoralmau| image:: https://github.com/victoralmau.png?size=40px + :target: https://github.com/victoralmau + :alt: victoralmau + +Current `maintainer `__: + +|maintainer-victoralmau| + +This module is part of the `OCA/hr-expense `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/hr_expense_employee_analytic_default/__init__.py b/hr_expense_employee_analytic_default/__init__.py new file mode 100644 index 000000000..4b76c7b2d --- /dev/null +++ b/hr_expense_employee_analytic_default/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from . import models diff --git a/hr_expense_employee_analytic_default/__manifest__.py b/hr_expense_employee_analytic_default/__manifest__.py new file mode 100644 index 000000000..f76551513 --- /dev/null +++ b/hr_expense_employee_analytic_default/__manifest__.py @@ -0,0 +1,13 @@ +# Copyright 2024 Tecnativa - Víctor Martínez +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +{ + "name": "Expense Employee Analytic Default", + "version": "18.0.1.0.0", + "category": "Human Resources", + "website": "https://github.com/OCA/hr-expense", + "author": "Tecnativa, Odoo Community Association (OCA)", + "license": "AGPL-3", + "depends": ["hr_expense"], + "installable": True, + "maintainers": ["victoralmau"], +} diff --git a/hr_expense_employee_analytic_default/i18n/hr_expense_employee_analytic_default.pot b/hr_expense_employee_analytic_default/i18n/hr_expense_employee_analytic_default.pot new file mode 100644 index 000000000..bcdd30f46 --- /dev/null +++ b/hr_expense_employee_analytic_default/i18n/hr_expense_employee_analytic_default.pot @@ -0,0 +1,24 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * hr_expense_employee_analytic_default +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 17.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: hr_expense_employee_analytic_default +#: model:ir.model,name:hr_expense_employee_analytic_default.model_account_analytic_distribution_model +msgid "Analytic Distribution Model" +msgstr "" + +#. module: hr_expense_employee_analytic_default +#: model:ir.model,name:hr_expense_employee_analytic_default.model_hr_expense +msgid "Expense" +msgstr "" diff --git a/hr_expense_employee_analytic_default/i18n/it.po b/hr_expense_employee_analytic_default/i18n/it.po new file mode 100644 index 000000000..5c57147f8 --- /dev/null +++ b/hr_expense_employee_analytic_default/i18n/it.po @@ -0,0 +1,27 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * hr_expense_employee_analytic_default +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 17.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2024-10-03 09:06+0000\n" +"Last-Translator: mymage \n" +"Language-Team: none\n" +"Language: it\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 5.6.2\n" + +#. module: hr_expense_employee_analytic_default +#: model:ir.model,name:hr_expense_employee_analytic_default.model_account_analytic_distribution_model +msgid "Analytic Distribution Model" +msgstr "Modello distribuzione analitica" + +#. module: hr_expense_employee_analytic_default +#: model:ir.model,name:hr_expense_employee_analytic_default.model_hr_expense +msgid "Expense" +msgstr "Spesa" diff --git a/hr_expense_employee_analytic_default/models/__init__.py b/hr_expense_employee_analytic_default/models/__init__.py new file mode 100644 index 000000000..86fa7c5ec --- /dev/null +++ b/hr_expense_employee_analytic_default/models/__init__.py @@ -0,0 +1,4 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import account_analytic_distribution_model +from . import hr_expense diff --git a/hr_expense_employee_analytic_default/models/account_analytic_distribution_model.py b/hr_expense_employee_analytic_default/models/account_analytic_distribution_model.py new file mode 100644 index 000000000..9d695f43d --- /dev/null +++ b/hr_expense_employee_analytic_default/models/account_analytic_distribution_model.py @@ -0,0 +1,20 @@ +# Copyright 2024 Tecnativa - Víctor Martínez +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo import api, models + + +class AccountAnalyticDistributionModel(models.Model): + _inherit = "account.analytic.distribution.model" + + @api.model + def _get_distribution(self, vals): + """If custom context is set, change partner to user partner of the employee + to get the correct distribution.""" + if self.env.context.get("hr_expense_employee_id"): + employee = self.env["hr.employee"].browse( + self.env.context.get("hr_expense_employee_id") + ) + if employee.address_id: + vals.update(partner_id=employee.address_id.id) + return super()._get_distribution(vals) diff --git a/hr_expense_employee_analytic_default/models/hr_expense.py b/hr_expense_employee_analytic_default/models/hr_expense.py new file mode 100644 index 000000000..b0d0447a9 --- /dev/null +++ b/hr_expense_employee_analytic_default/models/hr_expense.py @@ -0,0 +1,14 @@ +# Copyright 2024 Tecnativa - Víctor Martínez +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo import api, models + + +class HrExpense(models.Model): + _inherit = "hr.expense" + + @api.depends("employee_id") + def _compute_analytic_distribution(self): + """Set a specific context with the employee of the expense.""" + self = self.with_context(hr_expense_employee_id=self.employee_id.id) + return super()._compute_analytic_distribution() diff --git a/hr_expense_employee_analytic_default/pyproject.toml b/hr_expense_employee_analytic_default/pyproject.toml new file mode 100644 index 000000000..4231d0ccc --- /dev/null +++ b/hr_expense_employee_analytic_default/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/hr_expense_employee_analytic_default/readme/CONFIGURE.md b/hr_expense_employee_analytic_default/readme/CONFIGURE.md new file mode 100644 index 000000000..5859843a7 --- /dev/null +++ b/hr_expense_employee_analytic_default/readme/CONFIGURE.md @@ -0,0 +1,7 @@ +To configure this module, you need to: + +1. Enable the “Analytic Accounting” permission on the user +2. Go to an employee (or create a new one) and set a work address +3. Go to *Invocing \> Configuration \> Analytic Accounting |> + Analytic Distribution Models* and create a record that has as partner + the employee's work address. diff --git a/hr_expense_employee_analytic_default/readme/CONTRIBUTORS.md b/hr_expense_employee_analytic_default/readme/CONTRIBUTORS.md new file mode 100644 index 000000000..6dc92e514 --- /dev/null +++ b/hr_expense_employee_analytic_default/readme/CONTRIBUTORS.md @@ -0,0 +1,4 @@ +- [Tecnativa](https://www.tecnativa.com): + - Víctor Martínez + - Pedro M. Baeza +- `Heliconia Solutions Pvt. Ltd. `_ diff --git a/hr_expense_employee_analytic_default/readme/DESCRIPTION.md b/hr_expense_employee_analytic_default/readme/DESCRIPTION.md new file mode 100644 index 000000000..de58d15fc --- /dev/null +++ b/hr_expense_employee_analytic_default/readme/DESCRIPTION.md @@ -0,0 +1,2 @@ +This module allows to create Analytic Distribution Models for employees to be +applied to expenses. diff --git a/hr_expense_employee_analytic_default/readme/USAGE.md b/hr_expense_employee_analytic_default/readme/USAGE.md new file mode 100644 index 000000000..15e4a0fc8 --- /dev/null +++ b/hr_expense_employee_analytic_default/readme/USAGE.md @@ -0,0 +1,7 @@ +To use this module, you need to: + +1. Go to *Expenses* and create a new one. +2. The analytical distribution will be set according to + the analytic distribution model. +3. When changing the employee, the analytical distribution will + be updated. diff --git a/hr_expense_employee_analytic_default/static/description/icon.png b/hr_expense_employee_analytic_default/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/hr_expense_employee_analytic_default/static/description/icon.png differ diff --git a/hr_expense_employee_analytic_default/static/description/index.html b/hr_expense_employee_analytic_default/static/description/index.html new file mode 100644 index 000000000..1295bb0d2 --- /dev/null +++ b/hr_expense_employee_analytic_default/static/description/index.html @@ -0,0 +1,455 @@ + + + + + +Expense Employee Analytic Default + + + +
+

Expense Employee Analytic Default

+ + +

Beta License: AGPL-3 OCA/hr-expense Translate me on Weblate Try me on Runboat

+

This module allows to create Analytic Distribution Models for employees +to be applied to expenses.

+

Table of contents

+ +
+

Configuration

+

To configure this module, you need to:

+
    +
  1. Enable the “Analytic Accounting” permission on the user
  2. +
  3. Go to an employee (or create a new one) and set a work address
  4. +
  5. Go to Invocing > Configuration > Analytic Accounting |> Analytic +Distribution Models and create a record that has as partner the +employee’s work address.
  6. +
+
+
+

Usage

+

To use this module, you need to:

+
    +
  1. Go to Expenses and create a new one.
  2. +
  3. The analytical distribution will be set according to the analytic +distribution model.
  4. +
  5. When changing the employee, the analytical distribution will be +updated.
  6. +
+
+
+

Bug Tracker

+

Bugs are tracked on GitHub 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.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • Tecnativa
  • +
+
+
+

Contributors

+
    +
  • Tecnativa:
      +
    • Víctor Martínez
    • +
    • Pedro M. Baeza
    • +
    +
  • +
  • Heliconia Solutions Pvt. Ltd. <https://www.heliconia.io>_
  • +
+
+
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

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.

+

Current maintainer:

+

victoralmau

+

This module is part of the OCA/hr-expense project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/hr_expense_employee_analytic_default/tests/__init__.py b/hr_expense_employee_analytic_default/tests/__init__.py new file mode 100644 index 000000000..fc1b183fc --- /dev/null +++ b/hr_expense_employee_analytic_default/tests/__init__.py @@ -0,0 +1 @@ +from . import test_hr_expense_employee_analytic_default diff --git a/hr_expense_employee_analytic_default/tests/test_hr_expense_employee_analytic_default.py b/hr_expense_employee_analytic_default/tests/test_hr_expense_employee_analytic_default.py new file mode 100644 index 000000000..5a2efeaec --- /dev/null +++ b/hr_expense_employee_analytic_default/tests/test_hr_expense_employee_analytic_default.py @@ -0,0 +1,76 @@ +# Copyright 2024 Tecnativa - Víctor Martínez +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo.tests import Form, new_test_user + +from odoo.addons.base.tests.common import BaseCommon + + +class TestHrExpenseEmployeeAnalyticDefault(BaseCommon): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.user1 = new_test_user(cls.env, login="test_user_1") + cls.user1.action_create_employee() + cls.work_address = cls.env["res.partner"].create({"name": "Work address"}) + cls.user1.employee_ids.address_id = cls.work_address + cls.user2 = new_test_user(cls.env, login="test_user_2") + cls.user2.action_create_employee() + cls.plan = cls.env["account.analytic.plan"].create({"name": "Test plan"}) + cls.analytic_account = cls.env["account.analytic.account"].create( + { + "name": "Test analytic account", + "plan_id": cls.plan.id, + } + ) + cls.product = cls.env["product.product"].create( + { + "name": "Test expense product", + "can_be_expensed": True, + } + ) + cls.distribution = cls.env["account.analytic.distribution.model"].create( + { + "product_id": cls.product.id, + "partner_id": cls.work_address.id, + "analytic_distribution": {str(cls.analytic_account.id): 100.0}, + } + ) + + def test_hr_employee_1(self): + """Create expense for employee 1 + change to employee 2.""" + expense_form = Form( + self.env["hr.expense"].with_context( + default_employee_id=self.user1.employee_ids.id + ) + ) + expense_form.product_id = self.product + expense_form.name = "Test" + expense = expense_form.save() + self.assertEqual( + expense.analytic_distribution, self.distribution.analytic_distribution + ) + # As defined in _compute_analytic_distribution() of hr.expense, we need to + # leave the value empty because if there is no analytic distribution to apply, + # leave the value it had (maybe it is somewhat questionable). + expense.analytic_distribution = False + expense_form.employee_id = self.user2.employee_ids + expense = expense_form.save() + self.assertFalse(expense.analytic_distribution) + + def test_hr_employee_2(self): + """Create expense for employee 2 + change to employee 1.""" + expense_form = Form( + self.env["hr.expense"].with_context( + default_employee_id=self.user2.employee_ids.id + ) + ) + expense_form.product_id = self.product + expense_form.name = "Test" + expense = expense_form.save() + self.assertFalse(expense.analytic_distribution) + expense_form.employee_id = self.user1.employee_ids + expense = expense_form.save() + self.assertEqual( + expense.analytic_distribution, self.distribution.analytic_distribution + )