From ca1a5981b22ae6c299c11229111e778f593fa14d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phan=20Sainl=C3=A9ger?= Date: Tue, 5 May 2026 17:26:12 +0200 Subject: [PATCH] [MIG] hr_expense_analytic_account_preselect_with_projec: migrate to 18.0 --- .../README.rst | 66 +++++++++++++++++++ .../__init__.py | 1 + .../__manifest__.py | 25 +++++++ .../i18n/README | 1 + .../models/__init__.py | 1 + .../models/hr_expense.py | 14 ++++ .../views/hr_expense_views.xml | 18 +++++ 7 files changed, 126 insertions(+) create mode 100644 hr_expense_analytic_account_preselect_with_project/README.rst create mode 100644 hr_expense_analytic_account_preselect_with_project/__init__.py create mode 100644 hr_expense_analytic_account_preselect_with_project/__manifest__.py create mode 100644 hr_expense_analytic_account_preselect_with_project/i18n/README create mode 100644 hr_expense_analytic_account_preselect_with_project/models/__init__.py create mode 100644 hr_expense_analytic_account_preselect_with_project/models/hr_expense.py create mode 100644 hr_expense_analytic_account_preselect_with_project/views/hr_expense_views.xml diff --git a/hr_expense_analytic_account_preselect_with_project/README.rst b/hr_expense_analytic_account_preselect_with_project/README.rst new file mode 100644 index 0000000..8d378f7 --- /dev/null +++ b/hr_expense_analytic_account_preselect_with_project/README.rst @@ -0,0 +1,66 @@ +================================================== +HR Expense Analytic Account Preselect with Project +================================================== + +Preselect the analytic distribution on expenses based on the selected project. + +Description +=========== + +This module adds a ``Project`` field to expense forms. When a project is +selected, the analytic distribution is automatically set to the project's +analytic account (100%), so the user does not need to manually set the +analytic distribution. + +Installation +============ + +Use Odoo normal module installation procedure to install +``hr_expense_analytic_account_preselect_with_project``. + +This module depends on: + +* ``base`` (Odoo core) +* ``hr_expense`` (Odoo core) +* ``project`` (Odoo core) + +Usage +===== + +When creating an expense: + +1. Select a ``Project`` in the expense form. +2. The analytic distribution is automatically populated with the project's + analytic account at 100%. + +Known issues / Roadmap +====================== + +None yet. + +Bug Tracker +=========== + +Bugs are tracked on `our issues website `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smash it by providing detailed and welcomed feedback. + +Credits +======= + +Contributors +------------ + +* Clément Thomas + +Funders +------- + +The development of this module has been financially supported by: + +* Elabore (https://elabore.coop) + +Maintainer +---------- + +This module is maintained by Elabore. diff --git a/hr_expense_analytic_account_preselect_with_project/__init__.py b/hr_expense_analytic_account_preselect_with_project/__init__.py new file mode 100644 index 0000000..0650744 --- /dev/null +++ b/hr_expense_analytic_account_preselect_with_project/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/hr_expense_analytic_account_preselect_with_project/__manifest__.py b/hr_expense_analytic_account_preselect_with_project/__manifest__.py new file mode 100644 index 0000000..a8638ef --- /dev/null +++ b/hr_expense_analytic_account_preselect_with_project/__manifest__.py @@ -0,0 +1,25 @@ +# Copyright 2023 Stéphan Sainléger (Elabore) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "hr_expense_analytic_account_preselect_with_project", + "version": "18.0.1.0.0", + "author": "Elabore", + "website": "https://git.elabore.coop/elabore/hr-tools", + "maintainer": "Clément Thomas", + "license": "AGPL-3", + "category": "Tools", + "summary": "Preselect analytic distribution on expenses from project", + # any module necessary for this one to work correctly + "depends": [ + "base", + "hr_expense", + "project", + ], + "data": [ + "views/hr_expense_views.xml", + ], + "installable": True, + "auto_install": False, + "application": False, +} diff --git a/hr_expense_analytic_account_preselect_with_project/i18n/README b/hr_expense_analytic_account_preselect_with_project/i18n/README new file mode 100644 index 0000000..62197a1 --- /dev/null +++ b/hr_expense_analytic_account_preselect_with_project/i18n/README @@ -0,0 +1 @@ +This directory should contain the *.po for Odoo translation. diff --git a/hr_expense_analytic_account_preselect_with_project/models/__init__.py b/hr_expense_analytic_account_preselect_with_project/models/__init__.py new file mode 100644 index 0000000..86b1ea3 --- /dev/null +++ b/hr_expense_analytic_account_preselect_with_project/models/__init__.py @@ -0,0 +1 @@ +from . import hr_expense diff --git a/hr_expense_analytic_account_preselect_with_project/models/hr_expense.py b/hr_expense_analytic_account_preselect_with_project/models/hr_expense.py new file mode 100644 index 0000000..04282e9 --- /dev/null +++ b/hr_expense_analytic_account_preselect_with_project/models/hr_expense.py @@ -0,0 +1,14 @@ +from odoo import api, fields, models + + +class HrExpense(models.Model): + _inherit = "hr.expense" + + project_id = fields.Many2one("project.project", string="Projet", required=True) + + @api.onchange("project_id") + def set_analytic_account(self): + if self.project_id.account_id: + self.analytic_distribution = {str(self.project_id.account_id.id): 100} + else: + self.analytic_distribution = {} diff --git a/hr_expense_analytic_account_preselect_with_project/views/hr_expense_views.xml b/hr_expense_analytic_account_preselect_with_project/views/hr_expense_views.xml new file mode 100644 index 0000000..1adaa65 --- /dev/null +++ b/hr_expense_analytic_account_preselect_with_project/views/hr_expense_views.xml @@ -0,0 +1,18 @@ + + + + hr.expense.view.form.analytic.account.preselect.with.project + hr.expense + + + + + + + +