From 4778f55731eb22822d747c060b3d75a416f83058 Mon Sep 17 00:00:00 2001 From: Luis Rodriguez Date: Wed, 10 Jul 2024 13:26:39 +0200 Subject: [PATCH] [MIG] agreement_serviceprofile: Migration to 16.0 --- agreement_serviceprofile/__manifest__.py | 2 +- .../migrations/16.0.1.0.0/post-migration.py | 10 ++++++ .../models/agreement_serviceprofile.py | 8 ++--- agreement_serviceprofile/models/product.py | 34 ++++++------------- .../static/description/index.html | 11 +++--- .../tests/test_product.py | 7 ++-- agreement_serviceprofile/views/agreement.xml | 4 +-- .../views/agreement_serviceprofile.xml | 6 ++-- agreement_serviceprofile/views/product.xml | 14 +++++--- 9 files changed, 49 insertions(+), 47 deletions(-) create mode 100644 agreement_serviceprofile/migrations/16.0.1.0.0/post-migration.py diff --git a/agreement_serviceprofile/__manifest__.py b/agreement_serviceprofile/__manifest__.py index 0f5c7727..7b9c7e6b 100644 --- a/agreement_serviceprofile/__manifest__.py +++ b/agreement_serviceprofile/__manifest__.py @@ -4,7 +4,7 @@ { "name": "Agreement Service Profile", "summary": "Adds an Agreement Service Profile object", - "version": "14.0.1.1.1", + "version": "16.0.1.0.0", "category": "Contract", "author": "Pavlov Media, " "Open Source Integrators, " diff --git a/agreement_serviceprofile/migrations/16.0.1.0.0/post-migration.py b/agreement_serviceprofile/migrations/16.0.1.0.0/post-migration.py new file mode 100644 index 00000000..5efd18c4 --- /dev/null +++ b/agreement_serviceprofile/migrations/16.0.1.0.0/post-migration.py @@ -0,0 +1,10 @@ +from openupgradelib import openupgrade + + +@openupgrade.migrate() +def migrate(env, version): + openupgrade.logged_query( + env.cr, + """UPDATE product_template SET detailed_type = 'serviceprofile' + WHERE is_service_profile IS TRUE""", + ) diff --git a/agreement_serviceprofile/models/agreement_serviceprofile.py b/agreement_serviceprofile/models/agreement_serviceprofile.py index 68224ebd..a171fd15 100644 --- a/agreement_serviceprofile/models/agreement_serviceprofile.py +++ b/agreement_serviceprofile/models/agreement_serviceprofile.py @@ -32,12 +32,12 @@ def _default_stage_id(self): product_id = fields.Many2one( "product.template", "Service Product", - domain="[('is_serviceprofile', '=', True), ('type', '=', 'service')]", + domain="[('detailed_type', '=', 'serviceprofile'), ('type', '=', 'service')]", ) product_variant_id = fields.Many2one( "product.product", "Service Product Variant", - domain="[('is_serviceprofile', '=', True), ('type', '=', 'service')]", + domain="[('detailed_type', '=', 'serviceprofile'), ('type', '=', 'service')]", ) use_product_variant = fields.Boolean(default=False) partner_id = fields.Many2one(related="agreement_id.partner_id", string="Partner") @@ -45,7 +45,5 @@ def _default_stage_id(self): # 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_ids = stages.search([("stage_type", "=", "serviceprofile")], order=order) return stage_ids diff --git a/agreement_serviceprofile/models/product.py b/agreement_serviceprofile/models/product.py index 6f477e4f..73990639 100644 --- a/agreement_serviceprofile/models/product.py +++ b/agreement_serviceprofile/models/product.py @@ -1,34 +1,20 @@ # Copyright (C) 2019 - TODAY, Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo import api, fields, models +from odoo import fields, models class ProductTemplate(models.Model): _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.""", + detailed_type = fields.Selection( + selection_add=[ + ("serviceprofile", "Service Profile"), + ], + ondelete={"serviceprofile": "set service"}, ) - @api.onchange("is_serviceprofile") - def onchange_type(self): - if self.is_serviceprofile: - self.type = "service" - - -class ProductProduct(models.Model): - _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.""", - ) - - @api.onchange("is_serviceprofile") - def onchange_type(self): - if self.is_serviceprofile: - self.type = "service" + def _detailed_type_mapping(self): + type_mapping = super()._detailed_type_mapping() + type_mapping["serviceprofile"] = "service" + return type_mapping diff --git a/agreement_serviceprofile/static/description/index.html b/agreement_serviceprofile/static/description/index.html index c8da9403..072abfce 100644 --- a/agreement_serviceprofile/static/description/index.html +++ b/agreement_serviceprofile/static/description/index.html @@ -8,10 +8,11 @@ /* :Author: David Goodger (goodger@python.org) -:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $ +:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $ :Copyright: This stylesheet has been placed in the public domain. Default cascading style sheet for the HTML output of Docutils. +Despite the name, some widely supported CSS2 features are used. See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to customize this style sheet. @@ -274,7 +275,7 @@ margin-left: 2em ; margin-right: 2em } -pre.code .ln { color: grey; } /* line numbers */ +pre.code .ln { color: gray; } /* line numbers */ pre.code, code { background-color: #eeeeee } pre.code .comment, code .comment { color: #5C6576 } pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold } @@ -300,7 +301,7 @@ span.pre { white-space: pre } -span.problematic { +span.problematic, pre.problematic { color: red } span.section-subtitle { @@ -431,7 +432,9 @@

Contributors

Maintainers

This module is maintained by the OCA.

-Odoo Community Association + +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.

diff --git a/agreement_serviceprofile/tests/test_product.py b/agreement_serviceprofile/tests/test_product.py index 6afa3d83..56830155 100644 --- a/agreement_serviceprofile/tests/test_product.py +++ b/agreement_serviceprofile/tests/test_product.py @@ -14,13 +14,12 @@ def setUp(self): # 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() + product_01.detailed_type = "serviceprofile" + product_01.flush_recordset() 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() + product_02.detailed_type = "serviceprofile" self.assertEqual(product_02.type, "service") diff --git a/agreement_serviceprofile/views/agreement.xml b/agreement_serviceprofile/views/agreement.xml index 585d4875..6d94057d 100644 --- a/agreement_serviceprofile/views/agreement.xml +++ b/agreement_serviceprofile/views/agreement.xml @@ -27,12 +27,12 @@ diff --git a/agreement_serviceprofile/views/agreement_serviceprofile.xml b/agreement_serviceprofile/views/agreement_serviceprofile.xml index 817fa283..77625d1d 100644 --- a/agreement_serviceprofile/views/agreement_serviceprofile.xml +++ b/agreement_serviceprofile/views/agreement_serviceprofile.xml @@ -53,19 +53,19 @@ - +
diff --git a/agreement_serviceprofile/views/product.xml b/agreement_serviceprofile/views/product.xml index 574b8606..e268955a 100644 --- a/agreement_serviceprofile/views/product.xml +++ b/agreement_serviceprofile/views/product.xml @@ -9,10 +9,13 @@ - + - @@ -28,10 +31,13 @@ - + -