From bae75e8f43c3d93fa8dd2c090bebae4a7b2774ef Mon Sep 17 00:00:00 2001 From: EdgarRetes Date: Thu, 5 Dec 2024 12:57:07 -0600 Subject: [PATCH] [ADD] fieldservice_expense --- fieldservice_expense/README.rst | 35 ++++++++++++++ fieldservice_expense/__init__.py | 1 + fieldservice_expense/__manifest__.py | 19 ++++++++ fieldservice_expense/models/__init__.py | 2 + fieldservice_expense/models/fsm_order.py | 31 ++++++++++++ fieldservice_expense/models/hr_expense.py | 21 +++++++++ fieldservice_expense/pyproject.toml | 3 ++ fieldservice_expense/readme/USAGE.md | 4 ++ .../views/fsm_order_views.xml | 25 ++++++++++ .../views/hr_expense_views.xml | 47 +++++++++++++++++++ 10 files changed, 188 insertions(+) create mode 100644 fieldservice_expense/README.rst create mode 100644 fieldservice_expense/__init__.py create mode 100644 fieldservice_expense/__manifest__.py create mode 100644 fieldservice_expense/models/__init__.py create mode 100644 fieldservice_expense/models/fsm_order.py create mode 100644 fieldservice_expense/models/hr_expense.py create mode 100644 fieldservice_expense/pyproject.toml create mode 100644 fieldservice_expense/readme/USAGE.md create mode 100644 fieldservice_expense/views/fsm_order_views.xml create mode 100644 fieldservice_expense/views/hr_expense_views.xml diff --git a/fieldservice_expense/README.rst b/fieldservice_expense/README.rst new file mode 100644 index 0000000000..38929e8775 --- /dev/null +++ b/fieldservice_expense/README.rst @@ -0,0 +1,35 @@ +**This file is going to be generated by oca-gen-addon-readme.** + +*Manual changes will be overwritten.* + +Please provide content in the ``readme`` directory: + +* **DESCRIPTION.rst** (required) +* INSTALL.rst (optional) +* CONFIGURE.rst (optional) +* **USAGE.rst** (optional, highly recommended) +* DEVELOP.rst (optional) +* ROADMAP.rst (optional) +* HISTORY.rst (optional, recommended) +* **CONTRIBUTORS.rst** (optional, highly recommended) +* CREDITS.rst (optional) + +Content of this README will also be drawn from the addon manifest, +from keys such as name, authors, maintainers, development_status, +and license. + +A good, one sentence summary in the manifest is also highly recommended. + + +Automatic changelog generation +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`HISTORY.rst` can be auto generated using `towncrier `_. + +Just put towncrier compatible changelog fragments into `readme/newsfragments` +and the changelog file will be automatically generated and updated when a new fragment is added. + +Please refer to `towncrier` documentation to know more. + +NOTE: the changelog will be automatically generated when using `/ocabot merge $option`. +If you need to run it manually, refer to `OCA/maintainer-tools README `_. diff --git a/fieldservice_expense/__init__.py b/fieldservice_expense/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/fieldservice_expense/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/fieldservice_expense/__manifest__.py b/fieldservice_expense/__manifest__.py new file mode 100644 index 0000000000..d971bedd58 --- /dev/null +++ b/fieldservice_expense/__manifest__.py @@ -0,0 +1,19 @@ +# Copyright (C) 2018 Open Source Integrators +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +{ + "name": "Field Service - Expenses", + "summary": "Manage expenses of orders", + "version": "18.0.1.0.0", + "license": "AGPL-3", + "category": "TMS", + "author": "Open Source Integrators, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/field-service", + "depends": ["fieldservice", "hr_expense"], + "data": [ + "views/hr_expense_views.xml", + "views/fsm_order_views.xml", + ], + "demo": [], + "development_status": "Alpha", + "maintainers": ["max3903", "EdgarRetes"], +} diff --git a/fieldservice_expense/models/__init__.py b/fieldservice_expense/models/__init__.py new file mode 100644 index 0000000000..9dd4cf5532 --- /dev/null +++ b/fieldservice_expense/models/__init__.py @@ -0,0 +1,2 @@ +from . import hr_expense +from . import fsm_order diff --git a/fieldservice_expense/models/fsm_order.py b/fieldservice_expense/models/fsm_order.py new file mode 100644 index 0000000000..95536a1777 --- /dev/null +++ b/fieldservice_expense/models/fsm_order.py @@ -0,0 +1,31 @@ +# Copyright (C) 2024 Open Source Integrators +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import _, api, fields, models + + +class FSMOrder(models.Model): + _inherit = "fsm.order" + + expense_ids = fields.One2many( + "hr.expense", + "fsm_order_id", + ) + + expense_count = fields.Integer(compute="_compute_expenses") + + @api.depends("expense_ids") + def _compute_expenses(self): + for record in self: + record.expense_count = len(record.expense_ids) + + def action_view_expenses(self): + self.ensure_one() + return { + "type": "ir.actions.act_window", + "res_model": "hr.expense", + "view_mode": "list,form", + "domain": [("fsm_order_id", "=", self.id)], + "context": {"default_fsm_order_id": self.id}, + "name": _("Expenses for FSM Order %s") % self.name, + } diff --git a/fieldservice_expense/models/hr_expense.py b/fieldservice_expense/models/hr_expense.py new file mode 100644 index 0000000000..3378005d80 --- /dev/null +++ b/fieldservice_expense/models/hr_expense.py @@ -0,0 +1,21 @@ +# Copyright (C) 2024 Open Source Integrators +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import _, fields, models + + +class HrExpense(models.Model): + _inherit = "hr.expense" + + fsm_order_id = fields.Many2one("fsm.order") + + def action_view_order(self): + self.ensure_one() + return { + "type": "ir.actions.act_window", + "res_model": "fsm.order", + "view_mode": "form", + "res_id": self.fsm_order_id.id, + "target": "current", + "name": _("Order: %s") % self.fsm_order_id.name, + } diff --git a/fieldservice_expense/pyproject.toml b/fieldservice_expense/pyproject.toml new file mode 100644 index 0000000000..4231d0cccb --- /dev/null +++ b/fieldservice_expense/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/fieldservice_expense/readme/USAGE.md b/fieldservice_expense/readme/USAGE.md new file mode 100644 index 0000000000..fa12ab06cc --- /dev/null +++ b/fieldservice_expense/readme/USAGE.md @@ -0,0 +1,4 @@ +## Create expenses in orders +1. Go to FSM module. +2. Select or create a new order. +3. In the Expense page, create a new expense. diff --git a/fieldservice_expense/views/fsm_order_views.xml b/fieldservice_expense/views/fsm_order_views.xml new file mode 100644 index 0000000000..667c6a9f14 --- /dev/null +++ b/fieldservice_expense/views/fsm_order_views.xml @@ -0,0 +1,25 @@ + + + fsm.order.inherit.view.form + fsm.order + + + + + + + + + + + + + diff --git a/fieldservice_expense/views/hr_expense_views.xml b/fieldservice_expense/views/hr_expense_views.xml new file mode 100644 index 0000000000..b5f97c0e3b --- /dev/null +++ b/fieldservice_expense/views/hr_expense_views.xml @@ -0,0 +1,47 @@ + + + fsm.hr.expense.inherit.view.form + hr.expense + + + +
+ +
+
+ + + + + + + + + +
+
+ + + hr.expense.inherit.view.search + hr.expense + + + + + + + + +