Skip to content

Commit

Permalink
[MIG] agreement_serviceprofile: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
luisDIXMIT committed Oct 3, 2024
1 parent 35c9508 commit 70108e8
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 47 deletions.
2 changes: 1 addition & 1 deletion agreement_serviceprofile/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, "
Expand Down
10 changes: 10 additions & 0 deletions agreement_serviceprofile/migrations/16.0.1.0.0/post-migration.py
Original file line number Diff line number Diff line change
@@ -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""",
)
8 changes: 3 additions & 5 deletions agreement_serviceprofile/models/agreement_serviceprofile.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,18 @@ 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")

# 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
34 changes: 10 additions & 24 deletions agreement_serviceprofile/models/product.py
Original file line number Diff line number Diff line change
@@ -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
11 changes: 7 additions & 4 deletions agreement_serviceprofile/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@

/*
:Author: David Goodger ([email protected])
: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.
Expand Down Expand Up @@ -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 }
Expand All @@ -300,7 +301,7 @@
span.pre {
white-space: pre }

span.problematic {
span.problematic, pre.problematic {
color: red }

span.section-subtitle {
Expand Down Expand Up @@ -431,7 +432,9 @@ <h2><a class="toc-backref" href="#toc-entry-4">Contributors</a></h2>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-5">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
</a>
<p>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.</p>
Expand Down
6 changes: 2 additions & 4 deletions agreement_serviceprofile/tests/test_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@ 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"
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")
4 changes: 2 additions & 2 deletions agreement_serviceprofile/views/agreement.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@
<field name="use_product_variant" />
<field
name="product_variant_id"
context="{'default_is_serviceprofile': True, 'default_type': 'service'}"
context="{'default_detailed_type': 'serviceprofile', 'default_type': 'service'}"
attrs="{'invisible': [('use_product_variant', '=', False)], 'required': [('use_product_variant','!=', False)]}"
/>
<field
name="product_id"
context="{'default_is_serviceprofile': True, 'default_type': 'service'}"
context="{'default_detailed_type': 'serviceprofile', 'default_type': 'service'}"
attrs="{'invisible': [('use_product_variant', '!=', False)], 'required': [('use_product_variant','=', False)]}"
/>
</group>
Expand Down
6 changes: 3 additions & 3 deletions agreement_serviceprofile/views/agreement_serviceprofile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,19 @@
<group>
<field
name="product_id"
context="{'default_is_serviceprofile': True, 'default_type': 'service'}"
context="{'default_detailed_type': 'serviceprofile', 'default_type': 'service'}"
attrs="{'invisible': [('use_product_variant', '!=', False)], 'required': [('use_product_variant','=', False)]}"
/>
<field
name="product_variant_id"
context="{'default_is_serviceprofile': True, 'default_type': 'service'}"
context="{'default_detailed_type': 'serviceprofile', 'default_type': 'service'}"
attrs="{'invisible': [('use_product_variant', '=', False)], 'required': [('use_product_variant','!=', False)]}"
/>
<field name="use_product_variant" />
</group>
</group>
<group string="Notes">
<field name="notes" nolabel="1" widget="html" />
<field name="notes" nolabel="1" widget="html" colspan="2" />
</group>
</sheet>
<div class="oe_chatter">
Expand Down
14 changes: 10 additions & 4 deletions agreement_serviceprofile/views/product.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@
<field name="inherit_id" ref="product.product_template_form_view" />
<field name="arch" type="xml">
<xpath expr="//notebook" position="inside">
<page id="agreement" string="Service">
<page
id="agreement"
string="Service"
attrs="{'invisible': [('detailed_type', '!=', 'serviceprofile')]}"
>
<group>
<group id="agreement_left">
<field name="is_serviceprofile" />
</group>
<group id="agreement_right" />
</group>
Expand All @@ -28,10 +31,13 @@
<field name="inherit_id" ref="product.product_normal_form_view" />
<field name="arch" type="xml">
<xpath expr="//notebook" position="inside">
<page id="agreement" string="Service">
<page
id="agreement"
string="Service"
attrs="{'invisible': [('detailed_type', '!=', 'serviceprofile')]}"
>
<group>
<group id="agreement_left">
<field name="is_serviceprofile" />
</group>
<group id="agreement_right" />
</group>
Expand Down

0 comments on commit 70108e8

Please sign in to comment.