[14.0][MIG] agreement_serviceprofile (Version 12.0 to 14.0)

[MIG] Black

[MIG] Black
This commit is contained in:
Patrick Wilson
2021-05-04 13:49:14 -06:00
parent de369d4323
commit ef2dc5345f
11 changed files with 248 additions and 125 deletions

View File

@@ -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,
}

View File

@@ -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
)

View File

@@ -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

View File

@@ -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"},
)

View File

@@ -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"

View File

@@ -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

View File

@@ -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",
),
)

View File

@@ -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")

View File

@@ -1,33 +1,43 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<!-- Agreement Form View -->
<record id="agreement_fsm_order_form_view" model="ir.ui.view">
<field name="name">agreement.form.fsm.order.view</field>
<field name="model">agreement</field>
<field name="inherit_id" ref="agreement_legal.partner_agreement_form_view"/>
<field name="inherit_id" ref="agreement_legal.partner_agreement_form_view" />
<field name="arch" type="xml">
<notebook position="inside">
<page name="serviceprofiles" string="Service Profiles">
<field name="serviceprofile_ids">
<tree>
<field name="name"/>
<field name="product_id"/>
<field name="product_variant_id"/>
<field name="name" />
<field name="product_id" />
<field name="product_variant_id" />
</tree>
<form>
<group>
<group>
<field name="name"/>
<field name="name" />
</group>
<group>
<field name="use_product_variant"/>
<field name="product_variant_id" context="{'default_is_serviceprofile': True, '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'}" attrs="{'invisible': [('use_product_variant', '!=', False)], 'required': [('use_product_variant','=', False)]}"/>
<field name="use_product_variant" />
<field
name="product_variant_id"
context="{'default_is_serviceprofile': True, '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'}"
attrs="{'invisible': [('use_product_variant', '!=', False)], 'required': [('use_product_variant','=', False)]}"
/>
</group>
</group>
<group string="Notes">
<field name="notes" nolabel="1"
placeholder="Add notes here..."/>
<field
name="notes"
nolabel="1"
placeholder="Add notes here..."
/>
</group>
</form>
</field>

View File

@@ -1,4 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<!-- Agreement Service Profile List View-->
@@ -7,12 +6,12 @@
<field name="model">agreement.serviceprofile</field>
<field name="arch" type="xml">
<tree string="Service Profiles" default_order='agreement_id'>
<field name="name"/>
<field name="agreement_id"/>
<field name="partner_id"/>
<field name="product_id"/>
<field name="product_variant_id"/>
<field name="active" invisible="1"/>
<field name="name" />
<field name="agreement_id" />
<field name="partner_id" />
<field name="product_id" />
<field name="product_variant_id" />
<field name="active" invisible="1" />
</tree>
</field>
</record>
@@ -24,42 +23,54 @@
<field name="arch" type="xml">
<form string="Service Profile">
<header>
<field name="stage_id" widget="statusbar"
clickable="True"
options="{'fold_field': 'fold'}"
domain="[('stage_type', '=', 'serviceprofile')]"/>
<field
name="stage_id"
widget="statusbar"
clickable="True"
options="{'fold_field': 'fold'}"
domain="[('stage_type', '=', 'serviceprofile')]"
/>
</header>
<sheet>
<div class="oe_button_box" name="button_box">
<button name="toggle_active" type="object"
class="oe_stat_button" icon="fa-archive">
<field name="active" widget="boolean_button"
options="{'terminology': 'archive'}"/>
</button>
</div>
<div class="oe_button_box" name="button_box" />
<widget
name="web_ribbon"
title="Archived"
bg_color="bg-danger"
attrs="{'invisible': [('active', '=', True)]}"
/>
<field name="active" invisible="1" />
<div class="oe_title">
<label for="name" class="oe_edit_only"/>
<label for="name" class="oe_edit_only" />
<h1>
<field name="name"/>
<field name="name" />
</h1>
</div>
<group>
<group>
<field name="agreement_id"/>
<field name="agreement_id" />
</group>
<group>
<field name="product_id" context="{'default_is_serviceprofile': True, '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'}" attrs="{'invisible': [('use_product_variant', '=', False)], 'required': [('use_product_variant','!=', False)]}"/>
<field name="use_product_variant"/>
<field
name="product_id"
context="{'default_is_serviceprofile': True, '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'}"
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" />
</group>
</sheet>
<div class="oe_chatter">
<field name="message_follower_ids" widget="mail_followers"/>
<field name="message_ids" widget="mail_thread"/>
<field name="message_follower_ids" widget="mail_followers" />
<field name="message_ids" widget="mail_thread" />
</div>
</form>
</field>
@@ -76,10 +87,10 @@
<div class="oe_kanban_content">
<div>
<strong class="o_kanban_record_title">
<field name="name"/>
<field name="name" />
</strong>
</div>
<div class="oe_clear"/>
<div class="oe_clear" />
</div>
</t>
</templates>
@@ -93,15 +104,25 @@
<field name="model">agreement.serviceprofile</field>
<field name="arch" type="xml">
<search>
<filter string="Agreement" name="group_agreement"
icon="terp-partner"
context="{'group_by': 'agreement_id'}"/>
<filter string="Product" name="group_product"
icon="terp-product"
context="{'group_by': 'product_id'}"/>
<filter string="Product Variant" name="group_product"
icon="terp-product"
context="{'group_by': 'product_variant_id'}"/>
<field name="name" />
<filter
string="Agreement"
name="group_agreement"
icon="terp-partner"
context="{'group_by': 'agreement_id'}"
/>
<filter
string="Product"
name="group_product"
icon="terp-product"
context="{'group_by': 'product_id'}"
/>
<filter
string="Product Variant"
name="group_product"
icon="terp-product"
context="{'group_by': 'product_variant_id'}"
/>
</search>
</field>
</record>
@@ -120,17 +141,19 @@
</record>
<menuitem
name="Service Profiles"
id="agreement_serviceprofiles"
parent="agreement_legal.agreement_masterdata"
sequence="50"
action="agreement_serviceprofile_action"/>
name="Service Profiles"
id="agreement_serviceprofiles"
parent="agreement_legal.agreement_masterdata"
sequence="50"
action="agreement_serviceprofile_action"
/>
<menuitem
name="Service Profiles"
id="dashboard_serviceprofiles"
parent="agreement_legal.agreement_dashboard"
sequence="20"
action="agreement_serviceprofile_dashboard"/>
name="Service Profiles"
id="dashboard_serviceprofiles"
parent="agreement_legal.agreement_dashboard"
sequence="20"
action="agreement_serviceprofile_dashboard"
/>
</odoo>

View File

@@ -6,15 +6,15 @@
<record id="product_template_form_view" model="ir.ui.view">
<field name="name">product.template.form.view</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_form_view"/>
<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">
<group>
<group id="agreement_left">
<field name="is_serviceprofile"/>
<field name="is_serviceprofile" />
</group>
<group id="agreement_right"/>
<group id="agreement_right" />
</group>
</page>
</xpath>
@@ -25,15 +25,15 @@
<record id="product_product_form_view" model="ir.ui.view">
<field name="name">product.product.form.view</field>
<field name="model">product.product</field>
<field name="inherit_id" ref="product.product_normal_form_view"/>
<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">
<group>
<group id="agreement_left">
<field name="is_serviceprofile"/>
<field name="is_serviceprofile" />
</group>
<group id="agreement_right"/>
<group id="agreement_right" />
</group>
</page>
</xpath>