diff --git a/sale_project_task_description_template/README.rst b/sale_project_task_description_template/README.rst new file mode 100644 index 0000000000..d2f0e7484a --- /dev/null +++ b/sale_project_task_description_template/README.rst @@ -0,0 +1,135 @@ +.. image:: https://odoo-community.org/readme-banner-image + :target: https://odoo-community.org/get-involved?utm_source=readme + :alt: Odoo Community Association + +====================================== +Sale Project Task Description Template +====================================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:fc4721c380633a7a1854f4da47d823d8567e854b849849096e6e48d7dc348107 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/license-LGPL--3-blue.png + :target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html + :alt: License: LGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fproject-lightgray.png?logo=github + :target: https://github.com/OCA/project/tree/19.0/sale_project_task_description_template + :alt: OCA/project +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/project-19-0/project-19-0-sale_project_task_description_template + :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=19.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module extends the Project Task Description Template and integrates +it with Sales and Projects. When tasks are generated from sales order +lines, the task will automatically use the Task Description Template +defined on the related product. + +Optionally, you can include key information from the sales order line +(like product name and quantity) above the template, providing more +context directly in the task description. + +Key Features: + +- New field on product: assign a Task Description Template for service + products with Service Tracking set to 'Task' or 'Project & Task'. +- Optional boolean to include the sale order line info in the task + description. +- Automatic application of the template (and optionally the sales line + info) when creating tasks from sales orders. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +To use this module: + +- Create a Task Description Template + + - Go to Project → Configuration → Task Description Templates. + - Define a template with a name and description. + +- Assign the Template to a Product. + + - Open a Product and set it as a Service. + - Ensure that Service Tracking is set to Task or Project & Task. + - Set the Task Description Template field. + - Optionally, enable the Include Sale Line Info in Task checkbox to + add product and quantity information above the template in + generated tasks. + +- Create a Sale Order + + - Add the product(s) with assigned templates to a sales order. + - Confirm the order. + +- Generated Project Tasks + + - The tasks created from the sales order lines will automatically + include the description from the assigned template. + - If enabled, the sales line info (product and quantity) will appear + above the template in the task description. + +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 +------- + +* NICO SOLUTIONS - ENGINEERING & IT + +Contributors +------------ + +- Nils Coenen + +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-NICO-SOLUTIONS| image:: https://github.com/NICO-SOLUTIONS.png?size=40px + :target: https://github.com/NICO-SOLUTIONS + :alt: NICO-SOLUTIONS + +Current `maintainer `__: + +|maintainer-NICO-SOLUTIONS| + +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_task_description_template/__init__.py b/sale_project_task_description_template/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/sale_project_task_description_template/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/sale_project_task_description_template/__manifest__.py b/sale_project_task_description_template/__manifest__.py new file mode 100644 index 0000000000..4d567a0c6b --- /dev/null +++ b/sale_project_task_description_template/__manifest__.py @@ -0,0 +1,22 @@ +# Copyright 2025 NICO SOLUTIONS - ENGINEERING & IT +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl-3.0). +{ + "name": "Sale Project Task Description Template", + "summary": ( + "Apply task description templates from products to tasks, " + "with optional sale info" + ), + "version": "19.0.1.0.0", + "category": "Project", + "website": "https://github.com/OCA/project", + "author": "NICO SOLUTIONS - ENGINEERING & IT, Odoo Community Association (OCA)", + "maintainers": ["NICO-SOLUTIONS"], + "license": "LGPL-3", + "depends": ["project_task_description_template", "sale_timesheet"], + "data": [ + "views/product_template_views.xml", + ], + "installable": True, + "application": False, + "auto_install": False, +} diff --git a/sale_project_task_description_template/i18n/de.po b/sale_project_task_description_template/i18n/de.po new file mode 100644 index 0000000000..bb347f9520 --- /dev/null +++ b/sale_project_task_description_template/i18n/de.po @@ -0,0 +1,63 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_project_task_description_template +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 18.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2026-07-14 16:41+0000\n" +"Last-Translator: Nils Coenen \n" +"Language-Team: none\n" +"Language: de\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.15.2\n" + +#. module: sale_project_task_description_template +#. odoo-python +#: code:addons/sale_project_task_description_template/models/sale_order_line.py:0 +msgid "%(product)s - Qty: %(qty)s" +msgstr "%(product)s - Anzahl: %(qty)s" + +#. module: sale_project_task_description_template +#: model:ir.model.fields,help:sale_project_task_description_template.field_product_product__task_description_template_id +#: model:ir.model.fields,help:sale_project_task_description_template.field_product_template__task_description_template_id +msgid "Applies automatically when creating tasks" +msgstr "Wird beim Erstellen von Aufgaben automatisch angewendet." + +#. module: sale_project_task_description_template +#: model:ir.model.fields,help:sale_project_task_description_template.field_product_product__include_sale_line_info_in_task +#: model:ir.model.fields,help:sale_project_task_description_template.field_product_template__include_sale_line_info_in_task +msgid "" +"If enabled, the sale order line details (e.g., product and quantity) will be" +" added to the task description before the template content." +msgstr "" +"Wenn diese Option aktiviert ist, werden die Details der " +"Verkaufsauftragsposition (z. B. Produkt und Menge) vor dem Inhalt der " +"Vorlage zur Aufgabenbeschreibung hinzugefügt." + +#. module: sale_project_task_description_template +#: model:ir.model.fields,field_description:sale_project_task_description_template.field_product_product__include_sale_line_info_in_task +#: model:ir.model.fields,field_description:sale_project_task_description_template.field_product_template__include_sale_line_info_in_task +msgid "Include Sale Line Info in Task description" +msgstr "Verkaufsinformationen in die Aufgabenbeschreibung aufnehmen" + +#. module: sale_project_task_description_template +#: model:ir.model,name:sale_project_task_description_template.model_product_template +msgid "Product" +msgstr "Produkt" + +#. module: sale_project_task_description_template +#: model:ir.model,name:sale_project_task_description_template.model_sale_order_line +msgid "Sales Order Line" +msgstr "Auftragsposition" + +#. module: sale_project_task_description_template +#: model:ir.model.fields,field_description:sale_project_task_description_template.field_product_product__task_description_template_id +#: model:ir.model.fields,field_description:sale_project_task_description_template.field_product_template__task_description_template_id +#: model_terms:ir.ui.view,arch_db:sale_project_task_description_template.product_template_form_inherit_task_template +msgid "Task Description Template" +msgstr "Vorlage für Aufgabenbeschreibungen" diff --git a/sale_project_task_description_template/i18n/nl.po b/sale_project_task_description_template/i18n/nl.po new file mode 100644 index 0000000000..017dfa557c --- /dev/null +++ b/sale_project_task_description_template/i18n/nl.po @@ -0,0 +1,63 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_project_task_description_template +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 18.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2026-07-14 12:11+0000\n" +"Last-Translator: Bosd \n" +"Language-Team: none\n" +"Language: nl\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.15.2\n" + +#. module: sale_project_task_description_template +#. odoo-python +#: code:addons/sale_project_task_description_template/models/sale_order_line.py:0 +msgid "%(product)s - Qty: %(qty)s" +msgstr "%(product)s - Aantal: %(qty)s" + +#. module: sale_project_task_description_template +#: model:ir.model.fields,help:sale_project_task_description_template.field_product_product__task_description_template_id +#: model:ir.model.fields,help:sale_project_task_description_template.field_product_template__task_description_template_id +msgid "Applies automatically when creating tasks" +msgstr "Wordt automatisch toegepast bij het aanmaken van taken" + +#. module: sale_project_task_description_template +#: model:ir.model.fields,help:sale_project_task_description_template.field_product_product__include_sale_line_info_in_task +#: model:ir.model.fields,help:sale_project_task_description_template.field_product_template__include_sale_line_info_in_task +msgid "" +"If enabled, the sale order line details (e.g., product and quantity) will be" +" added to the task description before the template content." +msgstr "" +"Indien ingeschakeld, worden de details van de verkooporderregel (bijv. " +"product en aantal) toegevoegd aan de taakomschrijving vóór de inhoud van de " +"sjabloon." + +#. module: sale_project_task_description_template +#: model:ir.model.fields,field_description:sale_project_task_description_template.field_product_product__include_sale_line_info_in_task +#: model:ir.model.fields,field_description:sale_project_task_description_template.field_product_template__include_sale_line_info_in_task +msgid "Include Sale Line Info in Task description" +msgstr "Verkoopregelinfo opnemen in taakomschrijving" + +#. module: sale_project_task_description_template +#: model:ir.model,name:sale_project_task_description_template.model_product_template +msgid "Product" +msgstr "Product" + +#. module: sale_project_task_description_template +#: model:ir.model,name:sale_project_task_description_template.model_sale_order_line +msgid "Sales Order Line" +msgstr "Verkooporderregel" + +#. module: sale_project_task_description_template +#: model:ir.model.fields,field_description:sale_project_task_description_template.field_product_product__task_description_template_id +#: model:ir.model.fields,field_description:sale_project_task_description_template.field_product_template__task_description_template_id +#: model_terms:ir.ui.view,arch_db:sale_project_task_description_template.product_template_form_inherit_task_template +msgid "Task Description Template" +msgstr "Sjabloon taakomschrijving" diff --git a/sale_project_task_description_template/i18n/sale_project_task_description_template.pot b/sale_project_task_description_template/i18n/sale_project_task_description_template.pot new file mode 100644 index 0000000000..c9a1ffd639 --- /dev/null +++ b/sale_project_task_description_template/i18n/sale_project_task_description_template.pot @@ -0,0 +1,57 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_project_task_description_template +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 18.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: sale_project_task_description_template +#. odoo-python +#: code:addons/sale_project_task_description_template/models/sale_order_line.py:0 +msgid "%(product)s - Qty: %(qty)s" +msgstr "" + +#. module: sale_project_task_description_template +#: model:ir.model.fields,help:sale_project_task_description_template.field_product_product__task_description_template_id +#: model:ir.model.fields,help:sale_project_task_description_template.field_product_template__task_description_template_id +msgid "Applies automatically when creating tasks" +msgstr "" + +#. module: sale_project_task_description_template +#: model:ir.model.fields,help:sale_project_task_description_template.field_product_product__include_sale_line_info_in_task +#: model:ir.model.fields,help:sale_project_task_description_template.field_product_template__include_sale_line_info_in_task +msgid "" +"If enabled, the sale order line details (e.g., product and quantity) will be" +" added to the task description before the template content." +msgstr "" + +#. module: sale_project_task_description_template +#: model:ir.model.fields,field_description:sale_project_task_description_template.field_product_product__include_sale_line_info_in_task +#: model:ir.model.fields,field_description:sale_project_task_description_template.field_product_template__include_sale_line_info_in_task +msgid "Include Sale Line Info in Task description" +msgstr "" + +#. module: sale_project_task_description_template +#: model:ir.model,name:sale_project_task_description_template.model_product_template +msgid "Product" +msgstr "" + +#. module: sale_project_task_description_template +#: model:ir.model,name:sale_project_task_description_template.model_sale_order_line +msgid "Sales Order Line" +msgstr "" + +#. module: sale_project_task_description_template +#: model:ir.model.fields,field_description:sale_project_task_description_template.field_product_product__task_description_template_id +#: model:ir.model.fields,field_description:sale_project_task_description_template.field_product_template__task_description_template_id +#: model_terms:ir.ui.view,arch_db:sale_project_task_description_template.product_template_form_inherit_task_template +msgid "Task Description Template" +msgstr "" diff --git a/sale_project_task_description_template/models/__init__.py b/sale_project_task_description_template/models/__init__.py new file mode 100644 index 0000000000..83527162d0 --- /dev/null +++ b/sale_project_task_description_template/models/__init__.py @@ -0,0 +1,2 @@ +from . import product_template +from . import sale_order_line diff --git a/sale_project_task_description_template/models/product_template.py b/sale_project_task_description_template/models/product_template.py new file mode 100644 index 0000000000..fe4d6a9499 --- /dev/null +++ b/sale_project_task_description_template/models/product_template.py @@ -0,0 +1,20 @@ +# Copyright 2025 NICO SOLUTIONS - ENGINEERING & IT +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) + +from odoo import fields, models + + +class ProductTemplate(models.Model): + _inherit = "product.template" + + task_description_template_id = fields.Many2one( + "project.task.description.template", + string="Task Description Template", + help="Applies automatically when creating tasks", + ) + + include_sale_line_info_in_task = fields.Boolean( + string="Include Sale Line Info in Task description", + help="If enabled, the sale order line details (e.g., product and quantity) " + "will be added to the task description before the template content.", + ) diff --git a/sale_project_task_description_template/models/sale_order_line.py b/sale_project_task_description_template/models/sale_order_line.py new file mode 100644 index 0000000000..5f9956be9a --- /dev/null +++ b/sale_project_task_description_template/models/sale_order_line.py @@ -0,0 +1,33 @@ +# Copyright 2025 NICO SOLUTIONS - ENGINEERING & IT +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) + +from odoo import models + + +class SaleOrderLine(models.Model): + _inherit = "sale.order.line" + + def _timesheet_create_task_prepare_values(self, project): + values = super()._timesheet_create_task_prepare_values(project) + + product = self.product_id.product_tmpl_id + template = product.task_description_template_id + + if template: + values["description_template_id"] = template.id + + if product.include_sale_line_info_in_task: + product_info = self.env._( + "%(product)s - Qty: %(qty)s", + product=self.product_id.name, + qty=self.product_uom_qty, + ) + + if template and template.description: + values["description"] = f"{product_info}\n\n{template.description}" + else: + values["description"] = product_info + elif template and template.description: + values["description"] = template.description + + return values diff --git a/sale_project_task_description_template/pyproject.toml b/sale_project_task_description_template/pyproject.toml new file mode 100644 index 0000000000..4231d0cccb --- /dev/null +++ b/sale_project_task_description_template/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/sale_project_task_description_template/readme/CONTRIBUTORS.md b/sale_project_task_description_template/readme/CONTRIBUTORS.md new file mode 100644 index 0000000000..a3de8d2a4f --- /dev/null +++ b/sale_project_task_description_template/readme/CONTRIBUTORS.md @@ -0,0 +1 @@ +- Nils Coenen \<\> diff --git a/sale_project_task_description_template/readme/DESCRIPTION.md b/sale_project_task_description_template/readme/DESCRIPTION.md new file mode 100644 index 0000000000..b4a06a1fca --- /dev/null +++ b/sale_project_task_description_template/readme/DESCRIPTION.md @@ -0,0 +1,11 @@ +This module extends the Project Task Description Template and integrates it with Sales and Projects. +When tasks are generated from sales order lines, the task will automatically use the Task Description Template +defined on the related product. + +Optionally, you can include key information from the sales order line (like product name and quantity) above +the template, providing more context directly in the task description. + +Key Features: +- New field on product: assign a Task Description Template for service products with Service Tracking set to 'Task' or 'Project & Task'. +- Optional boolean to include the sale order line info in the task description. +- Automatic application of the template (and optionally the sales line info) when creating tasks from sales orders. diff --git a/sale_project_task_description_template/readme/USAGE.md b/sale_project_task_description_template/readme/USAGE.md new file mode 100644 index 0000000000..9d0d8a8c4d --- /dev/null +++ b/sale_project_task_description_template/readme/USAGE.md @@ -0,0 +1,16 @@ +To use this module: + +- Create a Task Description Template + - Go to Project → Configuration → Task Description Templates. + - Define a template with a name and description. +- Assign the Template to a Product. + - Open a Product and set it as a Service. + - Ensure that Service Tracking is set to Task or Project & Task. + - Set the Task Description Template field. + - Optionally, enable the Include Sale Line Info in Task checkbox to add product and quantity information above the template in generated tasks. +- Create a Sale Order + - Add the product(s) with assigned templates to a sales order. + - Confirm the order. +- Generated Project Tasks + - The tasks created from the sales order lines will automatically include the description from the assigned template. + - If enabled, the sales line info (product and quantity) will appear above the template in the task description. diff --git a/sale_project_task_description_template/static/description/icon.png b/sale_project_task_description_template/static/description/icon.png new file mode 100644 index 0000000000..3a0328b516 Binary files /dev/null and b/sale_project_task_description_template/static/description/icon.png differ diff --git a/sale_project_task_description_template/static/description/index.html b/sale_project_task_description_template/static/description/index.html new file mode 100644 index 0000000000..c1f5a96dd3 --- /dev/null +++ b/sale_project_task_description_template/static/description/index.html @@ -0,0 +1,479 @@ + + + + + +README.rst + + + +
+ + + +Odoo Community Association + +
+

Sale Project Task Description Template

+ +

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

+

This module extends the Project Task Description Template and integrates +it with Sales and Projects. When tasks are generated from sales order +lines, the task will automatically use the Task Description Template +defined on the related product.

+

Optionally, you can include key information from the sales order line +(like product name and quantity) above the template, providing more +context directly in the task description.

+

Key Features:

+
    +
  • New field on product: assign a Task Description Template for service +products with Service Tracking set to ‘Task’ or ‘Project & Task’.
  • +
  • Optional boolean to include the sale order line info in the task +description.
  • +
  • Automatic application of the template (and optionally the sales line +info) when creating tasks from sales orders.
  • +
+

Table of contents

+ +
+

Usage

+

To use this module:

+
    +
  • Create a Task Description Template
      +
    • Go to Project → Configuration → Task Description Templates.
    • +
    • Define a template with a name and description.
    • +
    +
  • +
  • Assign the Template to a Product.
      +
    • Open a Product and set it as a Service.
    • +
    • Ensure that Service Tracking is set to Task or Project & Task.
    • +
    • Set the Task Description Template field.
    • +
    • Optionally, enable the Include Sale Line Info in Task checkbox to +add product and quantity information above the template in +generated tasks.
    • +
    +
  • +
  • Create a Sale Order
      +
    • Add the product(s) with assigned templates to a sales order.
    • +
    • Confirm the order.
    • +
    +
  • +
  • Generated Project Tasks
      +
    • The tasks created from the sales order lines will automatically +include the description from the assigned template.
    • +
    • If enabled, the sales line info (product and quantity) will appear +above the template in the task description.
    • +
    +
  • +
+
+
+

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

+
    +
  • NICO SOLUTIONS - ENGINEERING & IT
  • +
+
+ +
+

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:

+

NICO-SOLUTIONS

+

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_task_description_template/tests/__init__.py b/sale_project_task_description_template/tests/__init__.py new file mode 100644 index 0000000000..3bd542de4f --- /dev/null +++ b/sale_project_task_description_template/tests/__init__.py @@ -0,0 +1,2 @@ +from . import test_product_template +from . import test_sale_order_line diff --git a/sale_project_task_description_template/tests/test_product_template.py b/sale_project_task_description_template/tests/test_product_template.py new file mode 100644 index 0000000000..b85d7b13e2 --- /dev/null +++ b/sale_project_task_description_template/tests/test_product_template.py @@ -0,0 +1,37 @@ +# Copyright 2025 NICO SOLUTIONS - ENGINEERING & IT +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) + +from odoo.tests.common import TransactionCase + + +class TestProductTemplate(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.task_template = cls.env["project.task.description.template"].create( + { + "name": "Test Task Template", + "description": "Template Description", + } + ) + cls.product = cls.env["product.template"].create( + { + "name": "Test Product", + "task_description_template_id": cls.task_template.id, + "include_sale_line_info_in_task": True, + } + ) + + def test_template_assignment(self): + self.assertEqual( + self.product.task_description_template_id, + self.task_template, + "Template should be saved correctly in the product.", + ) + + def test_flag_include_sale_line_info(self): + self.product.include_sale_line_info_in_task = False + self.assertFalse( + self.product.include_sale_line_info_in_task, + "Flag should be False after change.", + ) diff --git a/sale_project_task_description_template/tests/test_sale_order_line.py b/sale_project_task_description_template/tests/test_sale_order_line.py new file mode 100644 index 0000000000..0a9200303a --- /dev/null +++ b/sale_project_task_description_template/tests/test_sale_order_line.py @@ -0,0 +1,92 @@ +# Copyright 2025 NICO SOLUTIONS - ENGINEERING & IT +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) + +from odoo.tests.common import TransactionCase + + +class TestSaleOrderLine(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.task_template = cls.env["project.task.description.template"].create( + { + "name": "Test Template", + "description": "Template Description", + } + ) + cls.empty_template = cls.env["project.task.description.template"].create( + { + "name": "Empty Template", + "description": "", + } + ) + cls.product = cls.env["product.template"].create( + { + "name": "Test Product", + "task_description_template_id": cls.task_template.id, + "include_sale_line_info_in_task": True, + } + ) + cls.partner = cls.env["res.partner"].search([], limit=1) + cls.sale_order = cls.env["sale.order"].create({"partner_id": cls.partner.id}) + cls.project = cls.env["project.project"].create( + { + "name": "Test Project", + "billing_type": "not_billable", + "allow_timesheets": True, + } + ) + + def _prepare_task_values(self, include_sale_line_info=False, template=None, qty=1): + self.product.include_sale_line_info_in_task = include_sale_line_info + self.product.task_description_template_id = template or False + sale_line = self.env["sale.order.line"].create( + { + "order_id": self.sale_order.id, + "product_id": self.product.product_variant_id.id, + "product_uom_qty": qty, + } + ) + return sale_line._timesheet_create_task_prepare_values(project=self.project) + + def test_task_values_without_template(self): + values = self._prepare_task_values( + include_sale_line_info=False, template=None, qty=1 + ) + self.assertNotIn("description_template_id", values) + self.assertIn("description", values) + self.assertEqual(values["description"], "") + + def test_task_values_with_template_only(self): + values = self._prepare_task_values( + include_sale_line_info=False, template=self.task_template, qty=2 + ) + self.assertIn("description_template_id", values) + self.assertEqual(values["description_template_id"], self.task_template.id) + self.assertEqual(values["description"], self.task_template.description) + + def test_task_values_with_template_and_sale_info(self): + values = self._prepare_task_values( + include_sale_line_info=True, template=self.task_template, qty=3 + ) + expected_prefix = f"{self.product.name} - Qty: 3" + self.assertIn("description_template_id", values) + self.assertTrue(values["description"].startswith(expected_prefix)) + self.assertIn(self.task_template.description, values["description"]) + + def test_task_values_with_empty_template_only(self): + values = self._prepare_task_values( + include_sale_line_info=False, template=self.empty_template, qty=5 + ) + self.assertIn("description", values) + self.assertEqual(values["description"], "") + self.assertIn("description_template_id", values) + + def test_task_values_with_empty_template_and_sale_info(self): + values = self._prepare_task_values( + include_sale_line_info=True, template=self.empty_template, qty=4 + ) + expected_prefix = f"{self.product.name} - Qty: 4.0" + self.assertIn("description", values) + self.assertEqual(values["description"], expected_prefix) + self.assertIn("description_template_id", values) diff --git a/sale_project_task_description_template/views/product_template_views.xml b/sale_project_task_description_template/views/product_template_views.xml new file mode 100644 index 0000000000..0e38cb5e5b --- /dev/null +++ b/sale_project_task_description_template/views/product_template_views.xml @@ -0,0 +1,23 @@ + + + + + product.template.form.inherit.task.template + product.template + + + + + + + + +