[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 # Copyright (C) 2019 Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{ {
'name': 'Agreement Service Profile', "name": "Agreement Service Profile",
'summary': "Adds an Agreement Service Profile object", "summary": "Adds an Agreement Service Profile object",
'version': '12.0.1.2.0', "version": "14.0.1.0.0",
'category': 'Contract', "category": "Contract",
'author': 'Pavlov Media, ' "author": "Pavlov Media, "
'Open Source Integrators, ' "Open Source Integrators, "
'Odoo Community Association (OCA)', "Odoo Community Association (OCA)",
'website': 'https://github.com/oca/contract', "website": "https://github.com/OCA/contract",
'license': 'AGPL-3', "license": "AGPL-3",
'depends': ['agreement_legal'], "depends": ["agreement_legal"],
'data': [ "data": [
'data/serviceprofile_stage.xml', "data/serviceprofile_stage.xml",
'security/ir.model.access.csv', "security/ir.model.access.csv",
'views/product.xml', "views/product.xml",
'views/agreement_serviceprofile.xml', "views/agreement_serviceprofile.xml",
'views/agreement.xml', "views/agreement.xml",
], ],
'development_status': 'Beta', "development_status": "Beta",
'maintainers': [ "maintainers": [
'max3903', "max3903",
], ],
'installable': True, "installable": True,
} }

View File

@@ -5,9 +5,8 @@ from odoo import fields, models
class Agreement(models.Model): class Agreement(models.Model):
_inherit = 'agreement' _inherit = "agreement"
serviceprofile_ids = fields.One2many('agreement.serviceprofile', serviceprofile_ids = fields.One2many(
'agreement_id', "agreement.serviceprofile", "agreement_id", string="Service Profiles", copy=True
string="Service Profiles", )
copy=True)

View File

@@ -2,43 +2,51 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # 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): class AgreementServiceProfile(models.Model):
_name = 'agreement.serviceprofile' _name = "agreement.serviceprofile"
_inherit = 'mail.thread' _inherit = "mail.thread"
_description = 'Agreement Service Profiles' _description = "Agreement Service Profiles"
def _default_stage_id(self): 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) name = fields.Char(string="Name", required=True)
stage_id = fields.Many2one('agreement.stage', string="Stage", stage_id = fields.Many2one(
default=_default_stage_id, copy=False, "agreement.stage",
group_expand='_read_group_stage_ids',) string="Stage",
agreement_id = fields.Many2one('agreement', string="Agreement", default=_default_stage_id,
ondelete="cascade") copy=False,
active = fields.Boolean(string="Active", group_expand="_read_group_stage_ids",
default=True, )
help="If unchecked, it will allow you " + agreement_id = fields.Many2one("agreement", string="Agreement", ondelete="cascade")
"to hide this service profile" active = fields.Boolean(
" without removing it.") string="Active",
default=True,
help="If unchecked, it will allow you to hide this service profile "
"without removing it.",
)
notes = fields.Text(string="Notes") notes = fields.Text(string="Notes")
product_id = fields.Many2one('product.template', 'Service Product', product_id = fields.Many2one(
domain="[('is_serviceprofile', '=', True), " "product.template",
"('type', '=', 'service')]") "Service Product",
product_variant_id = fields.Many2one('product.product', 'Service Product Variant', domain="[('is_serviceprofile', '=', True), ('type', '=', 'service')]",
domain="[('is_serviceprofile', '=', True), " )
"('type', '=', 'service')]") product_variant_id = fields.Many2one(
use_product_variant = fields.Boolean('Use Product Variant', default=False) "product.product",
partner_id = fields.Many2one(related='agreement_id.partner_id', "Service Product Variant",
string='Partner') 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 # Used for Kanban grouped_by view
@api.model @api.model
def _read_group_stage_ids(self, stages, domain, order): def _read_group_stage_ids(self, stages, domain, order):
stage_ids = self.env["agreement.stage"].search( stage_ids = self.env["agreement.stage"].search(
[('stage_type', '=', 'serviceprofile')]) [("stage_type", "=", "serviceprofile")]
)
return stage_ids return stage_ids

View File

@@ -5,8 +5,9 @@ from odoo import fields, models
class AgreementStage(models.Model): class AgreementStage(models.Model):
_inherit = 'agreement.stage' _inherit = "agreement.stage"
stage_type = fields.Selection( 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): class ProductTemplate(models.Model):
_inherit = 'product.template' _inherit = "product.template"
is_serviceprofile = fields.Boolean( is_serviceprofile = fields.Boolean(
string="Create Service Profiles", string="Create Service Profiles",
help="""If True, this product will create a service profile on the 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): def onchange_type(self):
if self.is_serviceprofile: if self.is_serviceprofile:
self.type = 'service' self.type = "service"
class ProductProduct(models.Model): class ProductProduct(models.Model):
_inherit = 'product.product' _inherit = "product.product"
is_serviceprofile = fields.Boolean( is_serviceprofile = fields.Boolean(
string="Create Service Profiles", string="Create Service Profiles",
help="""If True, this product will create a service profile on the 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): def onchange_type(self):
if self.is_serviceprofile: 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> <odoo>
<!-- Agreement Form View --> <!-- Agreement Form View -->
<record id="agreement_fsm_order_form_view" model="ir.ui.view"> <record id="agreement_fsm_order_form_view" model="ir.ui.view">
<field name="name">agreement.form.fsm.order.view</field> <field name="name">agreement.form.fsm.order.view</field>
<field name="model">agreement</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"> <field name="arch" type="xml">
<notebook position="inside"> <notebook position="inside">
<page name="serviceprofiles" string="Service Profiles"> <page name="serviceprofiles" string="Service Profiles">
<field name="serviceprofile_ids"> <field name="serviceprofile_ids">
<tree> <tree>
<field name="name"/> <field name="name" />
<field name="product_id"/> <field name="product_id" />
<field name="product_variant_id"/> <field name="product_variant_id" />
</tree> </tree>
<form> <form>
<group> <group>
<group> <group>
<field name="name"/> <field name="name" />
</group> </group>
<group> <group>
<field name="use_product_variant"/> <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
<field name="product_id" context="{'default_is_serviceprofile': True, 'default_type': 'service'}" attrs="{'invisible': [('use_product_variant', '!=', False)], 'required': [('use_product_variant','=', False)]}"/> 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> </group>
<group string="Notes"> <group string="Notes">
<field name="notes" nolabel="1" <field
placeholder="Add notes here..."/> name="notes"
nolabel="1"
placeholder="Add notes here..."
/>
</group> </group>
</form> </form>
</field> </field>

View File

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

View File

@@ -6,15 +6,15 @@
<record id="product_template_form_view" model="ir.ui.view"> <record id="product_template_form_view" model="ir.ui.view">
<field name="name">product.template.form.view</field> <field name="name">product.template.form.view</field>
<field name="model">product.template</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"> <field name="arch" type="xml">
<xpath expr="//notebook" position="inside"> <xpath expr="//notebook" position="inside">
<page id="agreement" string="Service"> <page id="agreement" string="Service">
<group> <group>
<group id="agreement_left"> <group id="agreement_left">
<field name="is_serviceprofile"/> <field name="is_serviceprofile" />
</group> </group>
<group id="agreement_right"/> <group id="agreement_right" />
</group> </group>
</page> </page>
</xpath> </xpath>
@@ -25,15 +25,15 @@
<record id="product_product_form_view" model="ir.ui.view"> <record id="product_product_form_view" model="ir.ui.view">
<field name="name">product.product.form.view</field> <field name="name">product.product.form.view</field>
<field name="model">product.product</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"> <field name="arch" type="xml">
<xpath expr="//notebook" position="inside"> <xpath expr="//notebook" position="inside">
<page id="agreement" string="Service"> <page id="agreement" string="Service">
<group> <group>
<group id="agreement_left"> <group id="agreement_left">
<field name="is_serviceprofile"/> <field name="is_serviceprofile" />
</group> </group>
<group id="agreement_right"/> <group id="agreement_right" />
</group> </group>
</page> </page>
</xpath> </xpath>