diff --git a/sale_project_reimbursement_cost/README.rst b/sale_project_reimbursement_cost/README.rst new file mode 100644 index 0000000000..143a16a2ac --- /dev/null +++ b/sale_project_reimbursement_cost/README.rst @@ -0,0 +1,159 @@ +=============================== +Sale project reimbursement cost +=============================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:bad249e38e180277d68f401bdf0bd9385ca0561141736c76f646a7f277648b82 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Fproject-lightgray.png?logo=github + :target: https://github.com/OCA/project/tree/17.0/sale_project_reimbursement_cost + :alt: OCA/project +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/project-17-0/project-17-0-sale_project_reimbursement_cost + :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/project&target_branch=17.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allows the display of provisions and reimbursement costs in +the ``Project Updates`` dashboard. + +**Table of contents** + +.. contents:: + :local: + +Use Cases / Context +=================== + +In businesses, especially those in services or consulting, where +expenses may be incurred on behalf of a client but later need to be +reimbursed by the client, Odoo’s functionality for +``Re-Invoice Expenses`` products (without using the hr_expenses module) +lacks visibility of this information in the project dashboard. + +With this module, two sections are added to the project dashboard: + +- **Provisions**: Values invoiced to the client in advance to cover any + necessary expenses. This section displays the analytic entries + generated from customer invoices for specific products. +- **Reimbursements cost:** Values generated from vendor bills that need + to be charged to the client. Using Odoo’s functionality, these are + the sales order lines automatically created from a vendor bill when + the product is configured as ``Re-Invoice Expenses``. + +Configuration +============= + +**To automatically create a project from a sale order:** + +- Go to ``Sales > Products > Products``. +- Create a new product with the following options: + + - Product Type: Service + - Invoicing Policy: ``Prepaid/Fixed Price``. + - Create on Order: Set an option other than ``Nothing``. + +**For Provisions:** + +- Go to ``Sales > Products > Products``. +- Create a new product of type Service. + +**For Reimbursement:** + +- Go to ``Sales > Products > Products``. +- Create a new product with the following options: + + - ``Product Type``: Service + - Invoicing Policy: ``Based on Delivered Quantity (Manual)``. + - ``Re-Invoice Expenses``: At cost or Sales price + - Fill in the ``Provision Product`` field created in the previous + step. + +Usage +===== + +**To generate a new project from a sale order**: + +- Go to ``Sales > Orders > Quotations``. +- Create a new sales order and select the first product configured. +- Add a second line with the second configured product for + ``Provisions``. +- Confirm the sales order. +- Generated the invoice + +**To generate reimbursement costs**: + +- Go to ``Invoicing > Vendors > Bills``. +- Create a new bill and select the third product configured for + ``Reimbursement``. +- In the invoice line, set the analytic distribution with the analytic + account for the project. +- Confirm the bill, and a new line will be added to the sale order with + the reimbursement cost. +- While the provision has a remaining amount, a new line will be added + to the sale order with the product for Provisions, but with a + negative quantity. + +**Project status dashboard**: + +- Go to ``Project > Projects``. +- Search for the respective project. +- In the Kanban view, click the top-right icon to display project + settings, then click ``Reporting / Project Updates``. + +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 `__: + + - Pedro M. Baeza + - Carlos López + +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. + +This module is part of the `OCA/project `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/sale_project_reimbursement_cost/__init__.py b/sale_project_reimbursement_cost/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/sale_project_reimbursement_cost/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/sale_project_reimbursement_cost/__manifest__.py b/sale_project_reimbursement_cost/__manifest__.py new file mode 100644 index 0000000000..aa2df4a135 --- /dev/null +++ b/sale_project_reimbursement_cost/__manifest__.py @@ -0,0 +1,23 @@ +# Copyright 2024 Tecnativa - Carlos López +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +{ + "name": "Sale project reimbursement cost", + "version": "17.0.1.0.0", + "summary": """Display provisions and reimbursement costs + in the Project Updates dashboard.""", + "author": "Tecnativa,Odoo Community Association (OCA)", + "website": "https://github.com/OCA/project", + "category": "Sales", + "depends": [ + "sale_project", + ], + "data": ["views/product_template_views.xml", "views/sale_order_line_views.xml"], + "demo": ["demo/product_demo.xml"], + "assets": { + "web.assets_backend": [ + "sale_project_reimbursement_cost/static/src/components/project_right_side_panel/**/*", + ], + }, + "installable": True, + "license": "AGPL-3", +} diff --git a/sale_project_reimbursement_cost/demo/product_demo.xml b/sale_project_reimbursement_cost/demo/product_demo.xml new file mode 100644 index 0000000000..22ed13c27a --- /dev/null +++ b/sale_project_reimbursement_cost/demo/product_demo.xml @@ -0,0 +1,28 @@ + + + + + Provision + service + + + + + Service task + service + + + task_in_project + ordered_prepaid + + + Reimbursement + service + + + delivered_manual + cost + + + diff --git a/sale_project_reimbursement_cost/i18n/es.po b/sale_project_reimbursement_cost/i18n/es.po new file mode 100644 index 0000000000..0dda690a3b --- /dev/null +++ b/sale_project_reimbursement_cost/i18n/es.po @@ -0,0 +1,85 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_project_reimbursement_cost +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 17.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2024-12-10 11:48+0000\n" +"PO-Revision-Date: 2024-12-10 06:51-0500\n" +"Last-Translator: \n" +"Language-Team: \n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: \n" +"X-Generator: Poedit 3.0.1\n" + +#. module: sale_project_reimbursement_cost +#. odoo-javascript +#: code:addons/sale_project_reimbursement_cost/static/src/components/project_right_side_panel/project_right_side_panel.xml:0 +#, python-format +msgid "Amount" +msgstr "Importe" + +#. module: sale_project_reimbursement_cost +#. odoo-javascript +#: code:addons/sale_project_reimbursement_cost/static/src/components/project_right_side_panel/project_right_side_panel.xml:0 +#, python-format +msgid "Date" +msgstr "Fecha" + +#. module: sale_project_reimbursement_cost +#: model:ir.model,name:sale_project_reimbursement_cost.model_product_template +msgid "Product" +msgstr "Producto" + +#. module: sale_project_reimbursement_cost +#: model:ir.model,name:sale_project_reimbursement_cost.model_project_project +msgid "Project" +msgstr "Proyecto" + +#. module: sale_project_reimbursement_cost +#. odoo-javascript +#: code:addons/sale_project_reimbursement_cost/static/src/components/project_right_side_panel/project_right_side_panel.xml:0 +#: model:product.template,name:sale_project_reimbursement_cost.product_provision_product_template +#, python-format +msgid "Provision" +msgstr "Provisión" + +#. module: sale_project_reimbursement_cost +#: model:ir.model.fields,field_description:sale_project_reimbursement_cost.field_product_product__provision_product_id +#: model:ir.model.fields,field_description:sale_project_reimbursement_cost.field_product_template__provision_product_id +msgid "Provision Product" +msgstr "Producto para provisión" + +#. module: sale_project_reimbursement_cost +#. odoo-javascript +#: code:addons/sale_project_reimbursement_cost/static/src/components/project_right_side_panel/project_right_side_panel.xml:0 +#, python-format +msgid "Provisions" +msgstr "Provisiones" + +#. module: sale_project_reimbursement_cost +#: model:product.template,name:sale_project_reimbursement_cost.product_reimbursement_product_template +msgid "Reimbursement" +msgstr "Reembolso" + +#. module: sale_project_reimbursement_cost +#: model:ir.actions.act_window,name:sale_project_reimbursement_cost.sol_reimbursement_cost_action +msgid "Reimbursement cost" +msgstr "Reembolso de gastos" + +#. module: sale_project_reimbursement_cost +#: model:product.template,name:sale_project_reimbursement_cost.product_service_task_product_template +msgid "Service task" +msgstr "Tarea de servicio" + +#. module: sale_project_reimbursement_cost +#. odoo-javascript +#: code:addons/sale_project_reimbursement_cost/static/src/components/project_right_side_panel/project_right_side_panel.xml:0 +#, python-format +msgid "Total" +msgstr "Total" diff --git a/sale_project_reimbursement_cost/i18n/sale_project_reimbursement_cost.pot b/sale_project_reimbursement_cost/i18n/sale_project_reimbursement_cost.pot new file mode 100644 index 0000000000..aa18b8125a --- /dev/null +++ b/sale_project_reimbursement_cost/i18n/sale_project_reimbursement_cost.pot @@ -0,0 +1,83 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_project_reimbursement_cost +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 17.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2024-12-10 11:48+0000\n" +"PO-Revision-Date: 2024-12-10 11:48+0000\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: sale_project_reimbursement_cost +#. odoo-javascript +#: code:addons/sale_project_reimbursement_cost/static/src/components/project_right_side_panel/project_right_side_panel.xml:0 +#, python-format +msgid "Amount" +msgstr "" + +#. module: sale_project_reimbursement_cost +#. odoo-javascript +#: code:addons/sale_project_reimbursement_cost/static/src/components/project_right_side_panel/project_right_side_panel.xml:0 +#, python-format +msgid "Date" +msgstr "" + +#. module: sale_project_reimbursement_cost +#: model:ir.model,name:sale_project_reimbursement_cost.model_product_template +msgid "Product" +msgstr "" + +#. module: sale_project_reimbursement_cost +#: model:ir.model,name:sale_project_reimbursement_cost.model_project_project +msgid "Project" +msgstr "" + +#. module: sale_project_reimbursement_cost +#. odoo-javascript +#: code:addons/sale_project_reimbursement_cost/static/src/components/project_right_side_panel/project_right_side_panel.xml:0 +#: model:product.template,name:sale_project_reimbursement_cost.product_provision_product_template +#, python-format +msgid "Provision" +msgstr "" + +#. module: sale_project_reimbursement_cost +#: model:ir.model.fields,field_description:sale_project_reimbursement_cost.field_product_product__provision_product_id +#: model:ir.model.fields,field_description:sale_project_reimbursement_cost.field_product_template__provision_product_id +msgid "Provision Product" +msgstr "" + +#. module: sale_project_reimbursement_cost +#. odoo-javascript +#: code:addons/sale_project_reimbursement_cost/static/src/components/project_right_side_panel/project_right_side_panel.xml:0 +#, python-format +msgid "Provisions" +msgstr "" + +#. module: sale_project_reimbursement_cost +#: model:product.template,name:sale_project_reimbursement_cost.product_reimbursement_product_template +msgid "Reimbursement" +msgstr "" + +#. module: sale_project_reimbursement_cost +#: model:ir.actions.act_window,name:sale_project_reimbursement_cost.sol_reimbursement_cost_action +msgid "Reimbursement cost" +msgstr "" + +#. module: sale_project_reimbursement_cost +#: model:product.template,name:sale_project_reimbursement_cost.product_service_task_product_template +msgid "Service task" +msgstr "" + +#. module: sale_project_reimbursement_cost +#. odoo-javascript +#: code:addons/sale_project_reimbursement_cost/static/src/components/project_right_side_panel/project_right_side_panel.xml:0 +#, python-format +msgid "Total" +msgstr "" diff --git a/sale_project_reimbursement_cost/models/__init__.py b/sale_project_reimbursement_cost/models/__init__.py new file mode 100644 index 0000000000..0686f100e3 --- /dev/null +++ b/sale_project_reimbursement_cost/models/__init__.py @@ -0,0 +1,3 @@ +from . import product_template +from . import project_project +from . import account_move_line diff --git a/sale_project_reimbursement_cost/models/account_move_line.py b/sale_project_reimbursement_cost/models/account_move_line.py new file mode 100644 index 0000000000..4cb24acbe7 --- /dev/null +++ b/sale_project_reimbursement_cost/models/account_move_line.py @@ -0,0 +1,68 @@ +from odoo import models +from odoo.tools import float_compare + + +class AccountMoveLine(models.Model): + _inherit = "account.move.line" + + def _sale_create_reinvoice_sale_line(self): + """ + Generate an additional line in the sale order for the provision product + only if the remaining amount in the provision product is greater than 0. + - Sale lines with the same analytic account and reimbursement product. + - Analytic lines with the same analytic account and provision product. + """ + SaleLine = self.env["sale.order.line"] + AnalyticLine = self.env["account.analytic.line"] + map_sale_line_per_move = super()._sale_create_reinvoice_sale_line() + for line in self.filtered(lambda aml: aml.product_id.provision_product_id): + provision_product = line.product_id.provision_product_id + sale_lines = map_sale_line_per_move.get(line.id) or [] + for sale_line in sale_lines: + analytic_account_id = sale_line.order_id.analytic_account_id + provision_data = AnalyticLine.read_group( + [ + ("account_id", "=", analytic_account_id.id), + ("product_id", "=", provision_product.id), + ], + fields=["product_id", "amount:sum"], + groupby=["product_id"], + ) + if not provision_data: + continue + sale_reimbursement_data = SaleLine.read_group( + [ + ("order_id.analytic_account_id", "=", analytic_account_id.id), + ("product_id", "=", line.product_id.id), + ("id", "!=", sale_line.id), + ("is_expense", "=", True), + ], + fields=["product_id", "untaxed_amount_to_invoice:sum"], + groupby=["product_id"], + ) + reimbursement_amount = ( + sale_reimbursement_data[0]["untaxed_amount_to_invoice"] + if sale_reimbursement_data + else 0.0 + ) + amount_remainig = max( + provision_data[0]["amount"] - reimbursement_amount, 0 + ) + amount = min(amount_remainig, line.price_subtotal) + if ( + float_compare( + amount, 0.0, precision_rounding=line.currency_id.rounding + ) + <= 0 + ): + continue + default_values = { + "product_id": provision_product.id, + "name": f"{line.name} ({provision_product.display_name})", + "price_unit": amount, + "product_uom_qty": -1, + "order_id": sale_line.order_id.id, + "is_expense": False, + } + sale_line.copy(default_values) + return map_sale_line_per_move diff --git a/sale_project_reimbursement_cost/models/product_template.py b/sale_project_reimbursement_cost/models/product_template.py new file mode 100644 index 0000000000..5340757234 --- /dev/null +++ b/sale_project_reimbursement_cost/models/product_template.py @@ -0,0 +1,12 @@ +# Copyright 2024 Tecnativa - Carlos López +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from odoo import fields, models + + +class ProductTemplate(models.Model): + _inherit = "product.template" + + provision_product_id = fields.Many2one( + "product.product", + domain=[("type", "=", "service")], + ) diff --git a/sale_project_reimbursement_cost/models/project_project.py b/sale_project_reimbursement_cost/models/project_project.py new file mode 100644 index 0000000000..caa7ebab4a --- /dev/null +++ b/sale_project_reimbursement_cost/models/project_project.py @@ -0,0 +1,117 @@ +# Copyright 2024 Tecnativa - Carlos López +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from odoo import models +from odoo.tools import format_date + + +class ProjectProject(models.Model): + _inherit = "project.project" + + def get_panel_data(self): + panel_data = super().get_panel_data() + provision_items = self._get_provision_items() + return { + **panel_data, + "provision_items": {"data": provision_items}, + } + + def _get_provision_items(self): + if not self.user_has_groups("project.group_project_user"): + return [] + provision_items = self.get_provision_items_data() + reimbursement_items = self.get_reimbursement_items_data() + data = provision_items + reimbursement_items + data.sort(key=lambda x: f"{x.get('date')}_{x.get('id')}") + return data + + def get_reimbursement_items_data(self): + domain = self._get_reimbursement_items_domain() + sols = self.env["sale.order.line"].sudo().search(domain) + + def get_action(res_id): + """Return the action vals to call it in frontend to the sale lines""" + action_id = "sale_project_reimbursement_cost.sol_reimbursement_cost_action" + return {"action": {"name": action_id, "resId": res_id}} + + items = [] + for line in sols.with_context(with_price_unit=True): + item = dict( + { + "id": line.id, + "name": line.display_name, + "date": format_date(self.env, line.order_id.date_order), + "amount": -line.untaxed_amount_to_invoice, + }, + **get_action(line.id), + ) + items.append(item) + return items + + def _get_reimbursement_items_domain(self): + sale_items = self.sudo()._get_sale_order_items() + domain = [ + ("order_id", "in", sale_items.sudo().order_id.ids), + ("is_expense", "=", True), + ("qty_to_invoice", ">", 0), + ("state", "=", "sale"), + ("display_type", "=", False), + "|", + ("project_id", "in", self.ids + [False]), + ("id", "in", sale_items.ids), + ] + return domain + + def get_provision_items_data(self): + domain = self._get_provision_items_domain() + analytic_lines = ( + self.env["account.analytic.line"] + .sudo() + .search( + domain, + order="date,id", + ) + ) + + def get_action(res_id): + """Return the action vals to call it in frontend to the analytic lines""" + return { + "action": { + "name": "analytic.account_analytic_line_action_entries", + "resId": res_id, + } + } + + items = [] + for analytic_line in analytic_lines: + item = dict( + { + "id": analytic_line.id, + "name": analytic_line.display_name, + "date": format_date(self.env, analytic_line.date), + "amount": analytic_line.amount, + }, + **get_action(analytic_line.id), + ) + items.append(item) + return items + + def _get_provision_items_domain(self): + provision_products = self.sudo()._get_provision_products() + domain = [ + ("product_id", "in", provision_products.ids), + ("account_id", "=", self.analytic_account_id.id), + ] + return domain + + def _get_provision_products(self): + """Get the provision products set in the all products""" + provision_products = self.env["product.template"]._read_group( + domain=[("provision_product_id", "!=", False)], + groupby=[], + aggregates=["provision_product_id:recordset"], + ) + return ( + provision_products[0][0] + if provision_products + else self.env["product.product"] + ) diff --git a/sale_project_reimbursement_cost/pyproject.toml b/sale_project_reimbursement_cost/pyproject.toml new file mode 100644 index 0000000000..4231d0cccb --- /dev/null +++ b/sale_project_reimbursement_cost/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/sale_project_reimbursement_cost/readme/CONFIGURE.md b/sale_project_reimbursement_cost/readme/CONFIGURE.md new file mode 100644 index 0000000000..21dd3587a2 --- /dev/null +++ b/sale_project_reimbursement_cost/readme/CONFIGURE.md @@ -0,0 +1,23 @@ +**To automatically create a project from a sale order:** + +- Go to `Sales > Products > Products`. +- Create a new product with the following options: + - Product Type: Service + - Invoicing Policy: `Prepaid/Fixed Price`. + - Create on Order: Set an option other than `Nothing`. + + +**For Provisions:** + +- Go to `Sales > Products > Products`. +- Create a new product of type Service. + + +**For Reimbursement:** + +- Go to `Sales > Products > Products`. +- Create a new product with the following options: + - `Product Type`: Service + - Invoicing Policy: `Based on Delivered Quantity (Manual)`. + - `Re-Invoice Expenses`: At cost or Sales price + - Fill in the `Provision Product` field created in the previous step. \ No newline at end of file diff --git a/sale_project_reimbursement_cost/readme/CONTEXT.md b/sale_project_reimbursement_cost/readme/CONTEXT.md new file mode 100644 index 0000000000..5fd22b7ea1 --- /dev/null +++ b/sale_project_reimbursement_cost/readme/CONTEXT.md @@ -0,0 +1,6 @@ +In businesses, especially those in services or consulting, where expenses may be incurred on behalf of a client but later need to be reimbursed by the client, Odoo’s functionality for `Re-Invoice Expenses` products (without using the hr_expenses module) lacks visibility of this information in the project dashboard. + +With this module, two sections are added to the project dashboard: + +- **Provisions**: Values invoiced to the client in advance to cover any necessary expenses. This section displays the analytic entries generated from customer invoices for specific products. +- **Reimbursements cost:** Values generated from vendor bills that need to be charged to the client. Using Odoo’s functionality, these are the sales order lines automatically created from a vendor bill when the product is configured as `Re-Invoice Expenses`. \ No newline at end of file diff --git a/sale_project_reimbursement_cost/readme/CONTRIBUTORS.md b/sale_project_reimbursement_cost/readme/CONTRIBUTORS.md new file mode 100644 index 0000000000..76723133dd --- /dev/null +++ b/sale_project_reimbursement_cost/readme/CONTRIBUTORS.md @@ -0,0 +1,3 @@ +- [Tecnativa](https://www.tecnativa.com): + - Pedro M. Baeza + - Carlos López \ No newline at end of file diff --git a/sale_project_reimbursement_cost/readme/DESCRIPTION.md b/sale_project_reimbursement_cost/readme/DESCRIPTION.md new file mode 100644 index 0000000000..16f339c85f --- /dev/null +++ b/sale_project_reimbursement_cost/readme/DESCRIPTION.md @@ -0,0 +1 @@ +This module allows the display of provisions and reimbursement costs in the `Project Updates` dashboard. \ No newline at end of file diff --git a/sale_project_reimbursement_cost/readme/USAGE.md b/sale_project_reimbursement_cost/readme/USAGE.md new file mode 100644 index 0000000000..65ccccf08a --- /dev/null +++ b/sale_project_reimbursement_cost/readme/USAGE.md @@ -0,0 +1,23 @@ +**To generate a new project from a sale order**: + +- Go to `Sales > Orders > Quotations`. +- Create a new sales order and select the first product configured. +- Add a second line with the second configured product for `Provisions`. +- Confirm the sales order. +- Generated the invoice + + +**To generate reimbursement costs**: + +- Go to `Invoicing > Vendors > Bills`. +- Create a new bill and select the third product configured for `Reimbursement`. +- In the invoice line, set the analytic distribution with the analytic account for the project. +- Confirm the bill, and a new line will be added to the sale order with the reimbursement cost. +- While the provision has a remaining amount, a new line will be added to the sale order with the product for Provisions, but with a negative quantity. + + +**Project status dashboard**: + +- Go to `Project > Projects`. +- Search for the respective project. +- In the Kanban view, click the top-right icon to display project settings, then click `Reporting / Project Updates`. \ No newline at end of file diff --git a/sale_project_reimbursement_cost/static/description/icon.png b/sale_project_reimbursement_cost/static/description/icon.png new file mode 100644 index 0000000000..3a0328b516 Binary files /dev/null and b/sale_project_reimbursement_cost/static/description/icon.png differ diff --git a/sale_project_reimbursement_cost/static/description/index.html b/sale_project_reimbursement_cost/static/description/index.html new file mode 100644 index 0000000000..caae372e42 --- /dev/null +++ b/sale_project_reimbursement_cost/static/description/index.html @@ -0,0 +1,511 @@ + + + + + +Sale project reimbursement cost + + + +
+

Sale project reimbursement cost

+ + +

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

+

This module allows the display of provisions and reimbursement costs in +the Project Updates dashboard.

+

Table of contents

+ +
+

Use Cases / Context

+

In businesses, especially those in services or consulting, where +expenses may be incurred on behalf of a client but later need to be +reimbursed by the client, Odoo’s functionality for +Re-Invoice Expenses products (without using the hr_expenses module) +lacks visibility of this information in the project dashboard.

+

With this module, two sections are added to the project dashboard:

+
    +
  • Provisions: Values invoiced to the client in advance to cover any +necessary expenses. This section displays the analytic entries +generated from customer invoices for specific products.
  • +
  • Reimbursements cost: Values generated from vendor bills that need +to be charged to the client. Using Odoo’s functionality, these are +the sales order lines automatically created from a vendor bill when +the product is configured as Re-Invoice Expenses.
  • +
+
+
+

Configuration

+

To automatically create a project from a sale order:

+
    +
  • Go to Sales > Products > Products.
  • +
  • Create a new product with the following options:
      +
    • Product Type: Service
    • +
    • Invoicing Policy: Prepaid/Fixed Price.
    • +
    • Create on Order: Set an option other than Nothing.
    • +
    +
  • +
+

For Provisions:

+
    +
  • Go to Sales > Products > Products.
  • +
  • Create a new product of type Service.
  • +
+

For Reimbursement:

+
    +
  • Go to Sales > Products > Products.
  • +
  • Create a new product with the following options:
      +
    • Product Type: Service
    • +
    • Invoicing Policy: Based on Delivered Quantity (Manual).
    • +
    • Re-Invoice Expenses: At cost or Sales price
    • +
    • Fill in the Provision Product field created in the previous +step.
    • +
    +
  • +
+
+
+

Usage

+

To generate a new project from a sale order:

+
    +
  • Go to Sales > Orders > Quotations.
  • +
  • Create a new sales order and select the first product configured.
  • +
  • Add a second line with the second configured product for +Provisions.
  • +
  • Confirm the sales order.
  • +
  • Generated the invoice
  • +
+

To generate reimbursement costs:

+
    +
  • Go to Invoicing > Vendors > Bills.
  • +
  • Create a new bill and select the third product configured for +Reimbursement.
  • +
  • In the invoice line, set the analytic distribution with the analytic +account for the project.
  • +
  • Confirm the bill, and a new line will be added to the sale order with +the reimbursement cost.
  • +
  • While the provision has a remaining amount, a new line will be added +to the sale order with the product for Provisions, but with a +negative quantity.
  • +
+

Project status dashboard:

+
    +
  • Go to Project > Projects.
  • +
  • Search for the respective project.
  • +
  • In the Kanban view, click the top-right icon to display project +settings, then click Reporting / Project Updates.
  • +
+
+
+

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:
      +
    • Pedro M. Baeza
    • +
    • Carlos López
    • +
    +
  • +
+
+
+

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.

+

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

+

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

+
+
+
+ + diff --git a/sale_project_reimbursement_cost/static/src/components/project_right_side_panel/project_right_side_panel.esm.js b/sale_project_reimbursement_cost/static/src/components/project_right_side_panel/project_right_side_panel.esm.js new file mode 100644 index 0000000000..5f97119151 --- /dev/null +++ b/sale_project_reimbursement_cost/static/src/components/project_right_side_panel/project_right_side_panel.esm.js @@ -0,0 +1,23 @@ +/** @odoo-module */ + +import {ProjectRightSidePanel} from "@project/components/project_right_side_panel/project_right_side_panel"; +import {patch} from "@web/core/utils/patch"; + +patch(ProjectRightSidePanel.prototype, { + // --------------------------------------------------------------------- + // Handlers + // --------------------------------------------------------------------- + + /** + * @private + * @param {Object} params + */ + async onReimbursementItemActionClick(params) { + const action = await this.actionService.loadAction(params.name, this.context); + this.actionService.doAction({ + ...action, + res_id: params.resId, + views: [[false, "form"]], + }); + }, +}); diff --git a/sale_project_reimbursement_cost/static/src/components/project_right_side_panel/project_right_side_panel.xml b/sale_project_reimbursement_cost/static/src/components/project_right_side_panel/project_right_side_panel.xml new file mode 100644 index 0000000000..964f32616e --- /dev/null +++ b/sale_project_reimbursement_cost/static/src/components/project_right_side_panel/project_right_side_panel.xml @@ -0,0 +1,72 @@ + + + + + + + + Provisions + + + + + + + + + + + + + + + + + + + + + + + + +
ProvisionDateAmount
+ + + + + + + + +
Total +
+
+
+
+ +
diff --git a/sale_project_reimbursement_cost/tests/__init__.py b/sale_project_reimbursement_cost/tests/__init__.py new file mode 100644 index 0000000000..2cabfeab1b --- /dev/null +++ b/sale_project_reimbursement_cost/tests/__init__.py @@ -0,0 +1 @@ +from . import test_reimbursement_cost diff --git a/sale_project_reimbursement_cost/tests/test_reimbursement_cost.py b/sale_project_reimbursement_cost/tests/test_reimbursement_cost.py new file mode 100644 index 0000000000..7eab24c87b --- /dev/null +++ b/sale_project_reimbursement_cost/tests/test_reimbursement_cost.py @@ -0,0 +1,217 @@ +# Copyright 2024 Tecnativa - Carlos López +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo.tests import new_test_user, tagged +from odoo.tests.common import users + +from odoo.addons.account.tests.common import AccountTestInvoicingCommon +from odoo.addons.base.tests.common import DISABLED_MAIL_CONTEXT + + +@tagged("post_install", "-at_install") +class TestReimbursementCost(AccountTestInvoicingCommon): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.env = cls.env(context=dict(cls.env.context, **DISABLED_MAIL_CONTEXT)) + cls.Task = cls.env["project.task"] + cls.Product = cls.env["product.product"] + cls.SaleOrder = cls.env["sale.order"] + cls.SaleLine = cls.env["sale.order.line"] + cls.user = new_test_user( + cls.env, + login="test-user", + groups="sales_team.group_sale_salesman" + ",project.group_project_user" + ",analytic.group_analytic_accounting", + ) + cls.service_task = cls.env.ref( + "sale_project_reimbursement_cost.product_service_task" + ) + cls.service_provision = cls.env.ref( + "sale_project_reimbursement_cost.product_provision" + ) + cls.service_reimbursement = cls.env.ref( + "sale_project_reimbursement_cost.product_reimbursement" + ) + cls.sale_order = cls.SaleOrder.create( + { + "partner_id": cls.partner_a.id, + "partner_invoice_id": cls.partner_a.id, + "partner_shipping_id": cls.partner_a.id, + } + ) + cls.sol_task = cls.SaleLine.create( + { + "product_id": cls.service_task.id, + "product_uom_qty": 1, + "order_id": cls.sale_order.id, + } + ) + cls.sol_provision = cls.SaleLine.create( + { + "product_id": cls.service_provision.id, + "product_uom_qty": 1, + "order_id": cls.sale_order.id, + "price_unit": 1000, + } + ) + cls.bill_1 = cls.init_invoice("in_invoice", products=cls.service_reimbursement) + + @users("test-user") + def test_reimbursement_cost(self): + """ + Create a sale order with a task and a provision product. + Generate a bill with a reimbursement product by 400. + Check that the provision line is added to the sale order. + Invoice the sale order. + Generate a new bill with a reimbursement product by 600. + Check that the provision line is added to the sale order. + Invoice the sale order. + Generate a new bill with a reimbursement product by 100. + Check that the provision line is not added to the sale order. + Invoice the sale order. + """ + + def _get_provision_and_reimbursement(project): + project_report_values = project.get_panel_data() + provision_data = project_report_values["provision_items"]["data"] + provisions = list(filter(lambda x: x["amount"] > 0, provision_data)) + reimbursements = list(filter(lambda x: x["amount"] < 0, provision_data)) + return provisions, reimbursements + + # generate the project/task and provision + self.sale_order.action_confirm() + customer_invoice = self.sale_order._create_invoices() + customer_invoice.action_post() + self.assertTrue(self.sol_task.task_id) + self.assertTrue(self.sale_order.analytic_account_id) + project = self.sol_task.task_id.project_id + provision_items, reimbursement_items = _get_provision_and_reimbursement(project) + self.assertEqual(len(reimbursement_items), 0) + self.assertEqual(len(provision_items), 1) + self.assertEqual(provision_items[0]["amount"], 1000) + # generate the reimbursement + self.bill_1.invoice_line_ids.write( + { + "analytic_distribution": {project.analytic_account_id.id: 100}, + "price_unit": 400, + "quantity": 1, + } + ) + self.bill_1.action_post() + # Check that the new lines are added to the sale order + # 1 line for reimbursement and 1 line for provision + self.assertEqual(len(self.sale_order.order_line), 4) + reimbursement_line = self.sale_order.order_line.filtered("is_expense") + reimbursement_provision_line = self.sale_order.order_line.filtered( + lambda line: line.product_id == self.service_provision + and not line.is_expense + and line.product_uom_qty < 0 + ) + self.assertEqual(len(reimbursement_provision_line), 1) + self.assertEqual(reimbursement_line.untaxed_amount_to_invoice, 400) + provision_items, reimbursement_items = _get_provision_and_reimbursement(project) + self.assertEqual(len(provision_items), 1) + self.assertEqual(provision_items[0]["amount"], 1000) + self.assertEqual(len(reimbursement_items), 1) + self.assertEqual(reimbursement_items[0]["amount"], -400) + self.assertIn("Reimbursement", reimbursement_items[0]["name"]) + # invoice the sale order. + customer_invoice = self.sale_order._create_invoices(final=True) + customer_invoice.action_post() + provision_items, reimbursement_items = _get_provision_and_reimbursement(project) + self.assertEqual(len(provision_items), 1) + self.assertEqual(provision_items[0]["amount"], 1000) + self.assertEqual(len(reimbursement_items), 1) + self.assertEqual(reimbursement_items[0]["amount"], -400) + self.assertIn("Provision", reimbursement_items[0]["name"]) + # generate a second reimbursement by 600 + new_bill = self.bill_1.copy() + new_bill.invoice_date = "2024-01-01" + new_bill.invoice_line_ids.write( + { + "analytic_distribution": {project.analytic_account_id.id: 100}, + "price_unit": 600, + "quantity": 1, + } + ) + new_bill.action_post() + # Check that the new lines are added to the sale order + # 1 line for reimbursement and 1 line for provision + self.assertEqual(len(self.sale_order.order_line), 6) + reimbursement_line = self.sale_order.order_line.filtered("is_expense") + reimbursement_provision_line = self.sale_order.order_line.filtered( + lambda line: line.product_id == self.service_provision + and not line.is_expense + and line.product_uom_qty < 0 + ) + self.assertEqual(len(reimbursement_provision_line), 2) + self.assertEqual(len(reimbursement_line), 2) + self.assertEqual(reimbursement_line[0].untaxed_amount_to_invoice, 0) + self.assertEqual(reimbursement_line[1].untaxed_amount_to_invoice, 600) + provision_items, reimbursement_items = _get_provision_and_reimbursement(project) + self.assertEqual(len(provision_items), 1) + self.assertEqual(provision_items[0]["amount"], 1000) + self.assertEqual(len(reimbursement_items), 2) + self.assertEqual(reimbursement_items[0]["amount"], -400) + self.assertEqual(reimbursement_items[1]["amount"], -600) + self.assertIn("Reimbursement", reimbursement_items[0]["name"]) + self.assertIn("Reimbursement", reimbursement_items[1]["name"]) + # invoice the sale order. + customer_invoice = self.sale_order._create_invoices(final=True) + customer_invoice.action_post() + provision_items, reimbursement_items = _get_provision_and_reimbursement(project) + self.assertEqual(len(provision_items), 1) + self.assertEqual(provision_items[0]["amount"], 1000) + self.assertEqual(len(reimbursement_items), 2) + self.assertEqual(reimbursement_items[0]["amount"], -400) + self.assertEqual(reimbursement_items[1]["amount"], -600) + self.assertIn("Provision", reimbursement_items[0]["name"]) + # generate a new reimbursement by 100 + # but the provision line must be not added + # only the reimbursement line must be added + new_bill = self.bill_1.copy() + new_bill.invoice_date = "2024-01-01" + new_bill.invoice_line_ids.write( + { + "analytic_distribution": {project.analytic_account_id.id: 100}, + "price_unit": 100, + "quantity": 1, + } + ) + new_bill.action_post() + # Check that the new lines are added to the sale order + # 1 line for reimbursement and no line for provision + self.assertEqual(len(self.sale_order.order_line), 7) + reimbursement_line = self.sale_order.order_line.filtered("is_expense") + reimbursement_provision_line = self.sale_order.order_line.filtered( + lambda line: line.product_id == self.service_provision + and not line.is_expense + and line.product_uom_qty < 0 + ) + self.assertEqual(len(reimbursement_provision_line), 2) + self.assertEqual(len(reimbursement_line), 3) + self.assertEqual(reimbursement_line[0].untaxed_amount_to_invoice, 0) + self.assertEqual(reimbursement_line[1].untaxed_amount_to_invoice, 0) + self.assertEqual(reimbursement_line[2].untaxed_amount_to_invoice, 100) + provision_items, reimbursement_items = _get_provision_and_reimbursement(project) + self.assertEqual(len(provision_items), 1) + self.assertEqual(provision_items[0]["amount"], 1000) + self.assertEqual(len(reimbursement_items), 3) + self.assertEqual(reimbursement_items[0]["amount"], -400) + self.assertEqual(reimbursement_items[1]["amount"], -600) + self.assertEqual(reimbursement_items[2]["amount"], -100) + self.assertIn("Reimbursement", reimbursement_items[0]["name"]) + self.assertIn("Reimbursement", reimbursement_items[1]["name"]) + self.assertIn("Reimbursement", reimbursement_items[2]["name"]) + # invoice the sale order. + customer_invoice = self.sale_order._create_invoices(final=True) + customer_invoice.action_post() + provision_items, reimbursement_items = _get_provision_and_reimbursement(project) + self.assertEqual(len(provision_items), 1) + self.assertEqual(provision_items[0]["amount"], 1000) + self.assertEqual(len(reimbursement_items), 2) + self.assertEqual(reimbursement_items[0]["amount"], -400) + self.assertEqual(reimbursement_items[1]["amount"], -600) + self.assertIn("Provision", reimbursement_items[0]["name"]) diff --git a/sale_project_reimbursement_cost/views/product_template_views.xml b/sale_project_reimbursement_cost/views/product_template_views.xml new file mode 100644 index 0000000000..2b43305497 --- /dev/null +++ b/sale_project_reimbursement_cost/views/product_template_views.xml @@ -0,0 +1,23 @@ + + + + + view.product.template.form + product.template + + + + + + + + + diff --git a/sale_project_reimbursement_cost/views/sale_order_line_views.xml b/sale_project_reimbursement_cost/views/sale_order_line_views.xml new file mode 100644 index 0000000000..fa092255d8 --- /dev/null +++ b/sale_project_reimbursement_cost/views/sale_order_line_views.xml @@ -0,0 +1,10 @@ + + + + + Reimbursement cost + sale.order.line + tree,form + + +