From de9af0ae58545dcd50d4509b48c5deb7f929b627 Mon Sep 17 00:00:00 2001 From: ilo Date: Thu, 28 Nov 2024 14:03:26 -0300 Subject: [PATCH 1/2] [17.0][ADD] fieldservice_sale_recurring_agreement --- .../README.rst | 86 ++++ .../__init__.py | 1 + .../__manifest__.py | 25 + .../models/__init__.py | 2 + .../models/fsm_recurring.py | 16 + .../models/sale_order_line.py | 15 + .../pyproject.toml | 3 + .../readme/CONTRIBUTORS.md | 3 + .../readme/DESCRIPTION.md | 2 + .../readme/USAGE.md | 1 + .../static/description/index.html | 434 ++++++++++++++++++ .../tests/__init__.py | 5 + ...t_fieldservice_sale_recurring_agreement.py | 79 ++++ .../views/fsm_recurring.xml | 12 + 14 files changed, 684 insertions(+) create mode 100644 fieldservice_sale_recurring_agreement/README.rst create mode 100644 fieldservice_sale_recurring_agreement/__init__.py create mode 100644 fieldservice_sale_recurring_agreement/__manifest__.py create mode 100644 fieldservice_sale_recurring_agreement/models/__init__.py create mode 100644 fieldservice_sale_recurring_agreement/models/fsm_recurring.py create mode 100644 fieldservice_sale_recurring_agreement/models/sale_order_line.py create mode 100644 fieldservice_sale_recurring_agreement/pyproject.toml create mode 100644 fieldservice_sale_recurring_agreement/readme/CONTRIBUTORS.md create mode 100644 fieldservice_sale_recurring_agreement/readme/DESCRIPTION.md create mode 100644 fieldservice_sale_recurring_agreement/readme/USAGE.md create mode 100644 fieldservice_sale_recurring_agreement/static/description/index.html create mode 100644 fieldservice_sale_recurring_agreement/tests/__init__.py create mode 100644 fieldservice_sale_recurring_agreement/tests/test_fieldservice_sale_recurring_agreement.py create mode 100644 fieldservice_sale_recurring_agreement/views/fsm_recurring.xml diff --git a/fieldservice_sale_recurring_agreement/README.rst b/fieldservice_sale_recurring_agreement/README.rst new file mode 100644 index 0000000000..3ba76e1423 --- /dev/null +++ b/fieldservice_sale_recurring_agreement/README.rst @@ -0,0 +1,86 @@ +===================================== +Fieldservice Sale Recurring Agreement +===================================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:20c1df52e0b73ff6a68832ada45b84ff35a3b38d80f0568a582690f173f44f83 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Ffield--service-lightgray.png?logo=github + :target: https://github.com/OCA/field-service/tree/17.0/fieldservice_sale_recurring_agreement + :alt: OCA/field-service +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/field-service-17-0/field-service-17-0-fieldservice_sale_recurring_agreement + :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/field-service&target_branch=17.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allows you to propagate the sale agreement from the sale +order to the ``fsm.recurring`` model. This way you re-use the sale +agreement in the ``fsm.order`` created from the recurring. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +No specific usage instructions. + +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 +------- + +* Camptocamp SA +* Italo Lopes + +Contributors +------------ + +- `Camptocamp `__: + + - Italo Lopes + +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/field-service `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/fieldservice_sale_recurring_agreement/__init__.py b/fieldservice_sale_recurring_agreement/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/fieldservice_sale_recurring_agreement/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/fieldservice_sale_recurring_agreement/__manifest__.py b/fieldservice_sale_recurring_agreement/__manifest__.py new file mode 100644 index 0000000000..7ff82bdd61 --- /dev/null +++ b/fieldservice_sale_recurring_agreement/__manifest__.py @@ -0,0 +1,25 @@ +# Copyright 2024 Camptocamp SA (https://www.camptocamp.com). +# @author: Italo Lopes +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Fieldservice Sale Recurring Agreement", + "summary": "Fieldservice Sale Recurring Agreement", + "category": "Field Service", + "version": "17.0.1.0.0", + "author": "Camptocamp SA, Italo Lopes, Odoo Community Association (OCA)", + "license": "AGPL-3", + "maintainer": "Camptocamp, imlopes", + "depends": [ + # OCA/agreement + "agreement_sale", + # OCA/field-service + "fieldservice_agreement", + "fieldservice_sale_recurring", + ], + "website": "https://github.com/OCA/field-service", + "data": [ + "views/fsm_recurring.xml", + ], + "installable": True, +} diff --git a/fieldservice_sale_recurring_agreement/models/__init__.py b/fieldservice_sale_recurring_agreement/models/__init__.py new file mode 100644 index 0000000000..35fe5b32e7 --- /dev/null +++ b/fieldservice_sale_recurring_agreement/models/__init__.py @@ -0,0 +1,2 @@ +from . import fsm_recurring +from . import sale_order_line diff --git a/fieldservice_sale_recurring_agreement/models/fsm_recurring.py b/fieldservice_sale_recurring_agreement/models/fsm_recurring.py new file mode 100644 index 0000000000..61ebc47bd4 --- /dev/null +++ b/fieldservice_sale_recurring_agreement/models/fsm_recurring.py @@ -0,0 +1,16 @@ +# Copyright 2024 Camptocamp SA (https://www.camptocamp.com). +# @author: Italo Lopes +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class FSMRecurring(models.Model): + _inherit = "fsm.recurring" + + agreement_id = fields.Many2one("agreement", string="Agreement", copy=False) + + def _prepare_order_values(self, date=None): + res = super()._prepare_order_values(date) + res["agreement_id"] = self.agreement_id.id + return res diff --git a/fieldservice_sale_recurring_agreement/models/sale_order_line.py b/fieldservice_sale_recurring_agreement/models/sale_order_line.py new file mode 100644 index 0000000000..4d3427a34c --- /dev/null +++ b/fieldservice_sale_recurring_agreement/models/sale_order_line.py @@ -0,0 +1,15 @@ +# Copyright 2024 Camptocamp SA (https://www.camptocamp.com). +# @author: Italo Lopes +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import models + + +class SaleOrderLine(models.Model): + _inherit = "sale.order.line" + + def _field_create_fsm_recurring_prepare_values(self): + res = super()._field_create_fsm_recurring_prepare_values() + if self.order_id and self.order_id.agreement_id: + res["agreement_id"] = self.order_id.agreement_id.id + return res diff --git a/fieldservice_sale_recurring_agreement/pyproject.toml b/fieldservice_sale_recurring_agreement/pyproject.toml new file mode 100644 index 0000000000..4231d0cccb --- /dev/null +++ b/fieldservice_sale_recurring_agreement/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/fieldservice_sale_recurring_agreement/readme/CONTRIBUTORS.md b/fieldservice_sale_recurring_agreement/readme/CONTRIBUTORS.md new file mode 100644 index 0000000000..ef0db2bf63 --- /dev/null +++ b/fieldservice_sale_recurring_agreement/readme/CONTRIBUTORS.md @@ -0,0 +1,3 @@ +- [Camptocamp](https://camptocamp.com): + + > - Italo Lopes \<\> diff --git a/fieldservice_sale_recurring_agreement/readme/DESCRIPTION.md b/fieldservice_sale_recurring_agreement/readme/DESCRIPTION.md new file mode 100644 index 0000000000..6def8070e9 --- /dev/null +++ b/fieldservice_sale_recurring_agreement/readme/DESCRIPTION.md @@ -0,0 +1,2 @@ +This module allows you to propagate the sale agreement from the sale order to the ``fsm.recurring`` model. +This way you re-use the sale agreement in the ``fsm.order`` created from the recurring. diff --git a/fieldservice_sale_recurring_agreement/readme/USAGE.md b/fieldservice_sale_recurring_agreement/readme/USAGE.md new file mode 100644 index 0000000000..f08cd97a88 --- /dev/null +++ b/fieldservice_sale_recurring_agreement/readme/USAGE.md @@ -0,0 +1 @@ +No specific usage instructions. diff --git a/fieldservice_sale_recurring_agreement/static/description/index.html b/fieldservice_sale_recurring_agreement/static/description/index.html new file mode 100644 index 0000000000..755d780eee --- /dev/null +++ b/fieldservice_sale_recurring_agreement/static/description/index.html @@ -0,0 +1,434 @@ + + + + + +Fieldservice Sale Recurring Agreement + + + +
+

Fieldservice Sale Recurring Agreement

+ + +

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

+

This module allows you to propagate the sale agreement from the sale +order to the fsm.recurring model. This way you re-use the sale +agreement in the fsm.order created from the recurring.

+

Table of contents

+ +
+

Usage

+

No specific usage instructions.

+
+
+

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

+
    +
  • Camptocamp SA
  • +
  • Italo Lopes
  • +
+
+
+

Contributors

+ +
+
+

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/field-service project on GitHub.

+

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

+
+
+
+ + diff --git a/fieldservice_sale_recurring_agreement/tests/__init__.py b/fieldservice_sale_recurring_agreement/tests/__init__.py new file mode 100644 index 0000000000..fef9279f92 --- /dev/null +++ b/fieldservice_sale_recurring_agreement/tests/__init__.py @@ -0,0 +1,5 @@ +# Copyright 2024 Camptocamp SA (https://www.camptocamp.com). +# @author: Italo Lopes +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import test_fieldservice_sale_recurring_agreement diff --git a/fieldservice_sale_recurring_agreement/tests/test_fieldservice_sale_recurring_agreement.py b/fieldservice_sale_recurring_agreement/tests/test_fieldservice_sale_recurring_agreement.py new file mode 100644 index 0000000000..252fa666b7 --- /dev/null +++ b/fieldservice_sale_recurring_agreement/tests/test_fieldservice_sale_recurring_agreement.py @@ -0,0 +1,79 @@ +# Copyright 2024 Camptocamp SA (https://www.camptocamp.com). +# @author: Italo Lopes +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields +from odoo.tests.common import TransactionCase + + +class TestFieldserviceSaleRecurringAgreement(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.sale_order_model = cls.env["sale.order"].with_context(tracking_disable=True) + cls.sale_order_line_model = cls.env["sale.order.line"] + cls.fsm_recurring_model = cls.env["fsm.recurring"] + cls.agreement_model = cls.env["agreement"] + cls.product_model = cls.env["product.product"] + cls.partner_model = cls.env["res.partner"] + + cls.test_location = cls.env.ref("fieldservice.test_location") + cls.pricelist = cls.env["product.pricelist"].search([], limit=1) + + cls.partner = cls.partner_model.create({"name": "Test Partner"}) + cls.agreement = cls.agreement_model.create( + { + "name": "Test Agreement", + "code": "TestAgreement", + "start_date": fields.Date.today(), + "end_date": fields.Date.today(), + } + ) + cls.product = cls.product_model.create( + { + "name": "Test Product", + "type": "service", + "field_service_tracking": "recurring", + "fsm_recurring_template_id": cls.env.ref( + "fieldservice_recurring.recur_template_weekdays" + ).id, + } + ) + cls.sale_order = cls.sale_order_model.create( + { + "partner_id": cls.partner.id, + "fsm_location_id": cls.test_location.id, + "pricelist_id": cls.pricelist.id, + "agreement_id": cls.agreement.id, + } + ) + cls.sale_line_recurring = cls.env["sale.order.line"].create( + { + "name": cls.product.name, + "product_id": cls.product.id, + "product_uom_qty": 1, + "product_uom": cls.product.uom_id.id, + "price_unit": cls.product.list_price, + "order_id": cls.sale_order.id, + "tax_id": False, + } + ) + + def test_01_sale_order_with_agreement_propagation(self): + self.sale_order.action_confirm() + fsm_recurring = self.fsm_recurring_model.search( + [("sale_line_id", "=", self.sale_line_recurring.id)] + ) + prepare_recurring_values = ( + self.sale_line_recurring._field_create_fsm_recurring_prepare_values() + ) + self.assertEqual(prepare_recurring_values["agreement_id"], self.agreement.id) + + self.assertTrue(fsm_recurring) + self.assertEqual(fsm_recurring.agreement_id, self.agreement) + order_values = fsm_recurring._prepare_order_values() + self.assertEqual(order_values["agreement_id"], self.agreement.id) + + fsm_recurring.action_start() + for order in fsm_recurring.fsm_order_ids: + self.assertEqual(order.agreement_id, self.agreement) diff --git a/fieldservice_sale_recurring_agreement/views/fsm_recurring.xml b/fieldservice_sale_recurring_agreement/views/fsm_recurring.xml new file mode 100644 index 0000000000..477996da49 --- /dev/null +++ b/fieldservice_sale_recurring_agreement/views/fsm_recurring.xml @@ -0,0 +1,12 @@ + + + + fsm.recurring + + + + + + + + From 6671d4507da556aa5164e4da71cb55d37cd6260d Mon Sep 17 00:00:00 2001 From: ilo Date: Thu, 28 Nov 2024 14:04:52 -0300 Subject: [PATCH 2/2] Add dependency file for tests purposes --- test-requirements.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 test-requirements.txt diff --git a/test-requirements.txt b/test-requirements.txt new file mode 100644 index 0000000000..395af5e5f5 --- /dev/null +++ b/test-requirements.txt @@ -0,0 +1 @@ +odoo-addon-fieldservice_agreement @ git+https://github.com/OCA/field-service.git@refs/pull/1266/head#subdirectory=fieldservice_agreement