diff --git a/agreement_serviceprofile/__manifest__.py b/agreement_serviceprofile/__manifest__.py
index 6dfee4955..983f10a36 100644
--- a/agreement_serviceprofile/__manifest__.py
+++ b/agreement_serviceprofile/__manifest__.py
@@ -2,26 +2,26 @@
# Copyright (C) 2019 Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
- 'name': 'Agreement Service Profile',
- 'summary': "Adds an Agreement Service Profile object",
- 'version': '12.0.1.2.0',
- 'category': 'Contract',
- 'author': 'Pavlov Media, '
- 'Open Source Integrators, '
- 'Odoo Community Association (OCA)',
- 'website': 'https://github.com/oca/contract',
- 'license': 'AGPL-3',
- 'depends': ['agreement_legal'],
- 'data': [
- 'data/serviceprofile_stage.xml',
- 'security/ir.model.access.csv',
- 'views/product.xml',
- 'views/agreement_serviceprofile.xml',
- 'views/agreement.xml',
+ "name": "Agreement Service Profile",
+ "summary": "Adds an Agreement Service Profile object",
+ "version": "14.0.1.0.0",
+ "category": "Contract",
+ "author": "Pavlov Media, "
+ "Open Source Integrators, "
+ "Odoo Community Association (OCA)",
+ "website": "https://github.com/OCA/contract",
+ "license": "AGPL-3",
+ "depends": ["agreement_legal"],
+ "data": [
+ "data/serviceprofile_stage.xml",
+ "security/ir.model.access.csv",
+ "views/product.xml",
+ "views/agreement_serviceprofile.xml",
+ "views/agreement.xml",
],
- 'development_status': 'Beta',
- 'maintainers': [
- 'max3903',
+ "development_status": "Beta",
+ "maintainers": [
+ "max3903",
],
- 'installable': True,
+ "installable": True,
}
diff --git a/agreement_serviceprofile/models/agreement.py b/agreement_serviceprofile/models/agreement.py
index dbc42a49b..9f17ff2fe 100644
--- a/agreement_serviceprofile/models/agreement.py
+++ b/agreement_serviceprofile/models/agreement.py
@@ -5,9 +5,8 @@ from odoo import fields, models
class Agreement(models.Model):
- _inherit = 'agreement'
+ _inherit = "agreement"
- serviceprofile_ids = fields.One2many('agreement.serviceprofile',
- 'agreement_id',
- string="Service Profiles",
- copy=True)
+ serviceprofile_ids = fields.One2many(
+ "agreement.serviceprofile", "agreement_id", string="Service Profiles", copy=True
+ )
diff --git a/agreement_serviceprofile/models/agreement_serviceprofile.py b/agreement_serviceprofile/models/agreement_serviceprofile.py
index c2b2289dd..01dc5c2b4 100644
--- a/agreement_serviceprofile/models/agreement_serviceprofile.py
+++ b/agreement_serviceprofile/models/agreement_serviceprofile.py
@@ -2,43 +2,51 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-from odoo import fields, models, api
+from odoo import api, fields, models
class AgreementServiceProfile(models.Model):
- _name = 'agreement.serviceprofile'
- _inherit = 'mail.thread'
- _description = 'Agreement Service Profiles'
+ _name = "agreement.serviceprofile"
+ _inherit = "mail.thread"
+ _description = "Agreement Service Profiles"
def _default_stage_id(self):
- return self.env.ref('agreement_serviceprofile.servpro_stage_draft')
+ return self.env.ref("agreement_serviceprofile.servpro_stage_draft")
name = fields.Char(string="Name", required=True)
- stage_id = fields.Many2one('agreement.stage', string="Stage",
- default=_default_stage_id, copy=False,
- group_expand='_read_group_stage_ids',)
- agreement_id = fields.Many2one('agreement', string="Agreement",
- ondelete="cascade")
- active = fields.Boolean(string="Active",
- default=True,
- help="If unchecked, it will allow you " +
- "to hide this service profile"
- " without removing it.")
+ stage_id = fields.Many2one(
+ "agreement.stage",
+ string="Stage",
+ default=_default_stage_id,
+ copy=False,
+ group_expand="_read_group_stage_ids",
+ )
+ agreement_id = fields.Many2one("agreement", string="Agreement", ondelete="cascade")
+ active = fields.Boolean(
+ string="Active",
+ default=True,
+ help="If unchecked, it will allow you to hide this service profile "
+ "without removing it.",
+ )
notes = fields.Text(string="Notes")
- product_id = fields.Many2one('product.template', 'Service Product',
- domain="[('is_serviceprofile', '=', True), "
- "('type', '=', 'service')]")
- product_variant_id = fields.Many2one('product.product', 'Service Product Variant',
- domain="[('is_serviceprofile', '=', True), "
- "('type', '=', 'service')]")
- use_product_variant = fields.Boolean('Use Product Variant', default=False)
- partner_id = fields.Many2one(related='agreement_id.partner_id',
- string='Partner')
+ product_id = fields.Many2one(
+ "product.template",
+ "Service Product",
+ domain="[('is_serviceprofile', '=', True), ('type', '=', 'service')]",
+ )
+ product_variant_id = fields.Many2one(
+ "product.product",
+ "Service Product Variant",
+ domain="[('is_serviceprofile', '=', True), ('type', '=', 'service')]",
+ )
+ use_product_variant = fields.Boolean("Use Product Variant", default=False)
+ partner_id = fields.Many2one(related="agreement_id.partner_id", string="Partner")
# Used for Kanban grouped_by view
@api.model
def _read_group_stage_ids(self, stages, domain, order):
stage_ids = self.env["agreement.stage"].search(
- [('stage_type', '=', 'serviceprofile')])
+ [("stage_type", "=", "serviceprofile")]
+ )
return stage_ids
diff --git a/agreement_serviceprofile/models/agreement_stage.py b/agreement_serviceprofile/models/agreement_stage.py
index cf578022c..0d3a89659 100644
--- a/agreement_serviceprofile/models/agreement_stage.py
+++ b/agreement_serviceprofile/models/agreement_stage.py
@@ -5,8 +5,9 @@ from odoo import fields, models
class AgreementStage(models.Model):
- _inherit = 'agreement.stage'
+ _inherit = "agreement.stage"
stage_type = fields.Selection(
- selection_add=[('serviceprofile', 'Service Profile')]
+ selection_add=[("serviceprofile", "Service Profile")],
+ ondelete={"serviceprofile": "cascade"},
)
diff --git a/agreement_serviceprofile/models/product.py b/agreement_serviceprofile/models/product.py
index 55a216989..6f477e4f1 100644
--- a/agreement_serviceprofile/models/product.py
+++ b/agreement_serviceprofile/models/product.py
@@ -5,28 +5,30 @@ from odoo import api, fields, models
class ProductTemplate(models.Model):
- _inherit = 'product.template'
+ _inherit = "product.template"
is_serviceprofile = fields.Boolean(
string="Create Service Profiles",
help="""If True, this product will create a service profile on the
- agreement when the sales order is confirmed.""")
+ agreement when the sales order is confirmed.""",
+ )
- @api.onchange('is_serviceprofile')
+ @api.onchange("is_serviceprofile")
def onchange_type(self):
if self.is_serviceprofile:
- self.type = 'service'
+ self.type = "service"
class ProductProduct(models.Model):
- _inherit = 'product.product'
+ _inherit = "product.product"
is_serviceprofile = fields.Boolean(
string="Create Service Profiles",
help="""If True, this product will create a service profile on the
- agreement when the sales order is confirmed.""")
+ agreement when the sales order is confirmed.""",
+ )
- @api.onchange('is_serviceprofile')
+ @api.onchange("is_serviceprofile")
def onchange_type(self):
if self.is_serviceprofile:
- self.type = 'service'
+ self.type = "service"
diff --git a/agreement_serviceprofile/tests/__init__.py b/agreement_serviceprofile/tests/__init__.py
new file mode 100644
index 000000000..a8d2da582
--- /dev/null
+++ b/agreement_serviceprofile/tests/__init__.py
@@ -0,0 +1,4 @@
+# License LGPLv3.0 or later (https://www.gnu.org/licenses/lgpl-3.0.en.html).
+
+from . import test_product
+from . import test_agreement_serviceprofile
diff --git a/agreement_serviceprofile/tests/test_agreement_serviceprofile.py b/agreement_serviceprofile/tests/test_agreement_serviceprofile.py
new file mode 100644
index 000000000..7727d4e61
--- /dev/null
+++ b/agreement_serviceprofile/tests/test_agreement_serviceprofile.py
@@ -0,0 +1,50 @@
+# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html)
+
+from datetime import timedelta
+
+from odoo import fields
+from odoo.tests.common import TransactionCase
+
+
+class TestAgreementServiceProfile(TransactionCase):
+ def setUp(self):
+ super().setUp()
+ self.test_customer = self.env["res.partner"].create({"name": "TestCustomer"})
+ self.agreement_type = self.env["agreement.type"].create(
+ {
+ "name": "Test Agreement Type",
+ "domain": "sale",
+ }
+ )
+ self.test_agreement = self.env["agreement"].create(
+ {
+ "name": "TestAgreement",
+ "description": "Test",
+ "special_terms": "Test",
+ "partner_id": self.test_customer.id,
+ "start_date": fields.Date.today(),
+ "end_date": fields.Date.today() + timedelta(days=365),
+ }
+ )
+ self.test_serviceprofile = self.env["agreement.serviceprofile"].create(
+ {
+ "name": "TestServiceProfile",
+ "agreement_id": self.test_agreement.id,
+ }
+ )
+
+ # TEST 01: Check Default Stage
+ def test_default_stage_id(self):
+ sp_01 = self.test_serviceprofile
+ self.assertEqual(sp_01.stage_id.name, "Draft")
+
+ # TEST 02: Check Read Stages
+ def test_read_group_stage_ids(self):
+ sp_01 = self.test_serviceprofile
+ self.assertEqual(
+ sp_01._read_group_stage_ids(self.env["agreement.stage"], [], "id"),
+ self.env["agreement.stage"].search(
+ [("stage_type", "=", "serviceprofile")],
+ order="id",
+ ),
+ )
diff --git a/agreement_serviceprofile/tests/test_product.py b/agreement_serviceprofile/tests/test_product.py
new file mode 100644
index 000000000..6afa3d83d
--- /dev/null
+++ b/agreement_serviceprofile/tests/test_product.py
@@ -0,0 +1,26 @@
+# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html)
+
+from odoo.tests.common import TransactionCase
+
+
+class TestProduct(TransactionCase):
+ def setUp(self):
+ super().setUp()
+ self.test_product1 = self.env["product.template"].create(
+ {"name": "TestProduct"}
+ )
+ self.test_product2 = self.env["product.product"].create({"name": "TestProduct"})
+
+ # TEST 01: Test onchange_type product.template
+ def test_product_template_onchange_type(self):
+ product_01 = self.test_product1
+ product_01.is_serviceprofile = True
+ product_01.onchange_type()
+ self.assertEqual(product_01.type, "service")
+
+ # TEST 02: Test onchange_type product.product
+ def test_product_product_onchange_type(self):
+ product_02 = self.test_product2
+ product_02.is_serviceprofile = True
+ product_02.onchange_type()
+ self.assertEqual(product_02.type, "service")
diff --git a/agreement_serviceprofile/views/agreement.xml b/agreement_serviceprofile/views/agreement.xml
index 3cb0784e2..60856de1d 100644
--- a/agreement_serviceprofile/views/agreement.xml
+++ b/agreement_serviceprofile/views/agreement.xml
@@ -1,33 +1,43 @@
-
agreement.form.fsm.order.view
agreement
-
+
-
-
-
+
+
+
diff --git a/agreement_serviceprofile/views/agreement_serviceprofile.xml b/agreement_serviceprofile/views/agreement_serviceprofile.xml
index b680b433f..406e373e5 100644
--- a/agreement_serviceprofile/views/agreement_serviceprofile.xml
+++ b/agreement_serviceprofile/views/agreement_serviceprofile.xml
@@ -1,4 +1,3 @@
-
@@ -7,12 +6,12 @@
agreement.serviceprofile
-
-
-
-
-
-
+
+
+
+
+
+
@@ -24,42 +23,54 @@
@@ -76,10 +87,10 @@
@@ -93,15 +104,25 @@
agreement.serviceprofile
-
-
-
+
+
+
+
@@ -120,17 +141,19 @@
+ name="Service Profiles"
+ id="agreement_serviceprofiles"
+ parent="agreement_legal.agreement_masterdata"
+ sequence="50"
+ action="agreement_serviceprofile_action"
+ />
+ name="Service Profiles"
+ id="dashboard_serviceprofiles"
+ parent="agreement_legal.agreement_dashboard"
+ sequence="20"
+ action="agreement_serviceprofile_dashboard"
+ />
diff --git a/agreement_serviceprofile/views/product.xml b/agreement_serviceprofile/views/product.xml
index e227fdabb..574b86064 100644
--- a/agreement_serviceprofile/views/product.xml
+++ b/agreement_serviceprofile/views/product.xml
@@ -6,15 +6,15 @@
product.template.form.view
product.template
-
+
-
+
-
+
@@ -25,15 +25,15 @@
product.product.form.view
product.product
-
+
-
+
-
+