diff --git a/sale_project_reimbursement_cost/README.rst b/sale_project_reimbursement_cost/README.rst new file mode 100644 index 0000000000..458593f31a --- /dev/null +++ b/sale_project_reimbursement_cost/README.rst @@ -0,0 +1,162 @@ +=============================== +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. +- Confirm the sales order. + +**To generate provisions**: + +- Go to ``Invoicing > Customers > Invoices``. +- Create a new invoice and select the second product configured for + ``Provisions``. +- In the invoice line, set the analytic distribution with the analytic + account for the project. +- Confirm 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. + +**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..085d8b4687 --- /dev/null +++ b/sale_project_reimbursement_cost/__manifest__.py @@ -0,0 +1,22 @@ +# 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"], + "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/models/__init__.py b/sale_project_reimbursement_cost/models/__init__.py new file mode 100644 index 0000000000..07268d7308 --- /dev/null +++ b/sale_project_reimbursement_cost/models/__init__.py @@ -0,0 +1,2 @@ +from . import product_template +from . import project_project 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..9567c0f5e1 --- /dev/null +++ b/sale_project_reimbursement_cost/models/project_project.py @@ -0,0 +1,151 @@ +# 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.osv import expression + + +class ProjectProject(models.Model): + _inherit = "project.project" + + def get_panel_data(self): + panel_data = super().get_panel_data() + return { + **panel_data, + "reimbursement_items": self._get_reimbursement_items(), + "provision_items": self._get_provision_items(), + } + + def _get_reimbursement_items(self, with_action=True): + domain = self._get_reimbursement_items_domain() + return { + "total": self.env["sale.order.line"].sudo().search_count(domain), + "data": self.get_reimbursement_items_data( + domain, limit=5, with_action=with_action + ), + } + + def get_reimbursement_items_data( + self, domain=None, offset=0, limit=None, with_action=True + ): + if not self.user_has_groups("project.group_project_user"): + return [] + sols = ( + self.env["sale.order.line"] + .sudo() + .search( + domain or self._get_reimbursement_items_domain(), + offset=offset, + limit=limit, + ) + ) + + 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, + } + } + + return [ + { + **sol_read, + **get_action(sol_read["id"]), + } + for sol_read in sols.with_context(with_price_unit=True).read( + [ + "display_name", + "untaxed_amount_invoiced", + "untaxed_amount_to_invoice", + ] + ) + ] + + def _get_reimbursement_items_domain(self, additional_domain=None): + 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), + ] + if additional_domain: + domain = expression.AND([domain, additional_domain]) + return domain + + def _get_provision_items(self, with_action=True): + domain = self._get_provision_items_domain() + return { + "total": self.env["account.analytic.line"].sudo().search_count(domain), + "data": self.get_provision_items_data( + domain, limit=5, with_action=with_action + ), + } + + def get_provision_items_data( + self, domain=None, offset=0, limit=None, with_action=True + ): + if not self.user_has_groups("project.group_project_user"): + return [] + analytic_lines = ( + self.env["account.analytic.line"] + .sudo() + .search( + domain or self._get_provision_items_domain(), + offset=offset, + limit=limit, + 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, + } + } + + return [ + { + **analytic_line_read, + **get_action(analytic_line_read["id"]), + } + for analytic_line_read in analytic_lines.read( + [ + "display_name", + "amount", + "date", + ] + ) + ] + + def _get_provision_items_domain(self, additional_domain=None): + provision_products = self.sudo()._get_provision_products() + domain = [ + ("product_id", "in", provision_products.ids), + ("account_id", "=", self.analytic_account_id.id), + ] + if additional_domain: + domain = expression.AND([domain, additional_domain]) + 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..454a76a68b --- /dev/null +++ b/sale_project_reimbursement_cost/readme/USAGE.md @@ -0,0 +1,28 @@ +**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. +- Confirm the sales order. + + +**To generate provisions**: + +- Go to `Invoicing > Customers > Invoices`. +- Create a new invoice and select the second product configured for `Provisions`. +- In the invoice line, set the analytic distribution with the analytic account for the project. +- Confirm 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. + + +**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..2f90053139 --- /dev/null +++ b/sale_project_reimbursement_cost/static/description/index.html @@ -0,0 +1,514 @@ + + + + + +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.
  • +
  • Confirm the sales order.
  • +
+

To generate provisions:

+
    +
  • Go to Invoicing > Customers > Invoices.
  • +
  • Create a new invoice and select the second product configured for +Provisions.
  • +
  • In the invoice line, set the analytic distribution with the analytic +account for the project.
  • +
  • Confirm 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.
  • +
+

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..a0cd17cbda --- /dev/null +++ b/sale_project_reimbursement_cost/static/src/components/project_right_side_panel/project_right_side_panel.esm.js @@ -0,0 +1,72 @@ +/** @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, { + async _loadAdditionalReimbursementItems() { + const offset = this.state.data.reimbursement_items.data.length; + const totalRecords = this.state.data.reimbursement_items.total; + const limit = totalRecords - offset <= 5 ? totalRecords - offset : 5; + const reimbursement_items = await this.orm.call( + "project.project", + "get_reimbursement_items_data", + [this.projectId, undefined, offset, limit], + { + context: this.context, + } + ); + this.state.data.reimbursement_items.data = [ + ...this.state.data.reimbursement_items.data, + ...reimbursement_items, + ]; + }, + + async onLoadReimbursementLinesClick() { + const saleItems = this.state.data.reimbursement_items; + if (saleItems && saleItems.total > saleItems.data.length) { + await this._loadAdditionalReimbursementItems(); + } + }, + async _loadAdditionalProvisionItems() { + const offset = this.state.data.provision_items.data.length; + const totalRecords = this.state.data.provision_items.total; + const limit = totalRecords - offset <= 5 ? totalRecords - offset : 5; + const provision_items = await this.orm.call( + "project.project", + "get_provision_items_data", + [this.projectId, undefined, offset, limit], + { + context: this.context, + } + ); + this.state.data.provision_items.data = [ + ...this.state.data.provision_items.data, + ...provision_items, + ]; + }, + + async onLoadProvisionLinesClick() { + const saleItems = this.state.data.provision_items; + if (saleItems && saleItems.total > saleItems.data.length) { + await this._loadAdditionalProvisionItems(); + } + }, + + // --------------------------------------------------------------------- + // 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..c400031558 --- /dev/null +++ b/sale_project_reimbursement_cost/static/src/components/project_right_side_panel/project_right_side_panel.xml @@ -0,0 +1,174 @@ + + + + + + + + Provisions + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ProvisionDateAmount
+ + + + + + + + +
Total +
+ + Load more + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Reimbursement costInvoicedTo invoiceExpected
+ + + + + + + + + + +
Total
+ + Load more + +
+
+
+
+ +
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..de699793ab --- /dev/null +++ b/sale_project_reimbursement_cost/tests/test_reimbursement_cost.py @@ -0,0 +1,157 @@ +# 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.uom_hour = cls.env.ref("uom.product_uom_hour") + product_vals = { + "name": "Service", + "type": "service", + "uom_id": cls.uom_hour.id, + "uom_po_id": cls.uom_hour.id, + } + cls.service_task = cls.Product.create( + dict( + product_vals, + name="Service task", + service_tracking="task_in_project", + service_policy="ordered_prepaid", + ) + ) + cls.service_provision = cls.Product.create(dict(product_vals, name="Provision")) + cls.service_reimbursement = cls.Product.create( + dict( + product_vals, + name="Reimbursement", + service_policy="delivered_manual", + expense_policy="cost", + provision_product_id=cls.service_provision.id, + ) + ) + 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.bill_1 = cls.init_invoice("in_invoice", products=cls.service_reimbursement) + cls.invoice_provision_1 = cls.init_invoice( + "out_invoice", products=cls.service_provision + ) + + @users("test-user") + def test_reimbursement_cost(self): + # generate the project/task + self.sale_order.action_confirm() + self.sale_order._create_invoices() + self.assertTrue(self.sol_task.task_id) + self.assertTrue(self.sale_order.analytic_account_id) + project = self.sol_task.task_id.project_id + project_report_values = project.get_panel_data() + self.assertEqual( + project_report_values["reimbursement_items"], {"total": 0.0, "data": []} + ) + self.assertEqual( + project_report_values["provision_items"], {"total": 0.0, "data": []} + ) + # generate the provision + self.invoice_provision_1.invoice_line_ids.write( + { + "analytic_distribution": {project.analytic_account_id.id: 100}, + "price_unit": 1000, + } + ) + self.invoice_provision_1.action_post() + project_report_values = project.get_panel_data() + provision_items = project_report_values["provision_items"] + self.assertEqual( + project_report_values["reimbursement_items"], {"total": 0.0, "data": []} + ) + self.assertEqual(provision_items["total"], 1) + self.assertEqual(len(provision_items["data"]), 1) + self.assertEqual(provision_items["data"][0]["amount"], 1000) + # generate the reimbursement + self.bill_1.invoice_line_ids.write( + { + "analytic_distribution": {project.analytic_account_id.id: 100}, + "price_unit": 100, + "quantity": 4, + } + ) + self.bill_1.action_post() + # check the new line is added to sale order + self.assertEqual(len(self.sale_order.order_line), 2) + reimbursement_line = self.sale_order.order_line.filtered("is_expense") + self.assertEqual(reimbursement_line.qty_to_invoice, 4) + project_report_values = project.get_panel_data() + provision_items = project_report_values["provision_items"] + reimbursement_items = project_report_values["reimbursement_items"] + self.assertEqual(provision_items["total"], 1) + self.assertEqual(len(provision_items["data"]), 1) + self.assertEqual(provision_items["data"][0]["amount"], 1000) + self.assertEqual(reimbursement_items["total"], 1) + self.assertEqual(len(reimbursement_items["data"]), 1) + self.assertEqual(reimbursement_items["data"][0]["untaxed_amount_invoiced"], 0) + self.assertEqual( + reimbursement_items["data"][0]["untaxed_amount_to_invoice"], 400 + ) + # partially invoice the sale order. + customer_invoice = self.sale_order._create_invoices() + invoice_line_reimbursement = customer_invoice.invoice_line_ids.filtered( + lambda x: x.product_id == self.service_reimbursement + ) + invoice_line_reimbursement.write({"quantity": 2}) + customer_invoice.action_post() + project_report_values = project.get_panel_data() + provision_items = project_report_values["provision_items"] + reimbursement_items = project_report_values["reimbursement_items"] + self.assertEqual(provision_items["total"], 1) + self.assertEqual(len(provision_items["data"]), 1) + self.assertEqual(provision_items["data"][0]["amount"], 1000) + self.assertEqual(reimbursement_items["total"], 1) + self.assertEqual(len(reimbursement_items["data"]), 1) + self.assertEqual(reimbursement_items["data"][0]["untaxed_amount_invoiced"], 200) + self.assertEqual( + reimbursement_items["data"][0]["untaxed_amount_to_invoice"], 200 + ) + # full invoice the sale order. + customer_invoice = self.sale_order._create_invoices() + customer_invoice.action_post() + project_report_values = project.get_panel_data() + provision_items = project_report_values["provision_items"] + reimbursement_items = project_report_values["reimbursement_items"] + self.assertEqual(provision_items["total"], 1) + self.assertEqual(len(provision_items["data"]), 1) + self.assertEqual(provision_items["data"][0]["amount"], 1000) + self.assertEqual(reimbursement_items["total"], 0) + self.assertEqual(len(reimbursement_items["data"]), 0) 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 + + +