mirror of
https://github.com/OCA/contract.git
synced 2025-02-13 17:57:24 +02:00
[14.0][MIG] agreement_serviceprofile (Version 12.0 to 14.0)
[MIG] Black [MIG] Black
This commit is contained in:
@@ -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,
|
||||
}
|
||||
|
||||
@@ -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
|
||||
)
|
||||
|
||||
@@ -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",
|
||||
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.")
|
||||
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
|
||||
|
||||
@@ -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"},
|
||||
)
|
||||
|
||||
@@ -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"
|
||||
|
||||
4
agreement_serviceprofile/tests/__init__.py
Normal file
4
agreement_serviceprofile/tests/__init__.py
Normal 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
|
||||
@@ -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",
|
||||
),
|
||||
)
|
||||
26
agreement_serviceprofile/tests/test_product.py
Normal file
26
agreement_serviceprofile/tests/test_product.py
Normal 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")
|
||||
@@ -1,4 +1,3 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<!-- Agreement Form View -->
|
||||
<record id="agreement_fsm_order_form_view" model="ir.ui.view">
|
||||
@@ -21,13 +20,24 @@
|
||||
</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="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>
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
|
||||
<!-- Agreement Service Profile List View-->
|
||||
@@ -24,19 +23,23 @@
|
||||
<field name="arch" type="xml">
|
||||
<form string="Service Profile">
|
||||
<header>
|
||||
<field name="stage_id" widget="statusbar"
|
||||
<field
|
||||
name="stage_id"
|
||||
widget="statusbar"
|
||||
clickable="True"
|
||||
options="{'fold_field': 'fold'}"
|
||||
domain="[('stage_type', '=', 'serviceprofile')]"/>
|
||||
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" />
|
||||
<h1>
|
||||
@@ -48,8 +51,16 @@
|
||||
<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="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>
|
||||
@@ -93,15 +104,25 @@
|
||||
<field name="model">agreement.serviceprofile</field>
|
||||
<field name="arch" type="xml">
|
||||
<search>
|
||||
<filter string="Agreement" name="group_agreement"
|
||||
<field name="name" />
|
||||
<filter
|
||||
string="Agreement"
|
||||
name="group_agreement"
|
||||
icon="terp-partner"
|
||||
context="{'group_by': 'agreement_id'}"/>
|
||||
<filter string="Product" name="group_product"
|
||||
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"
|
||||
context="{'group_by': 'product_id'}"
|
||||
/>
|
||||
<filter
|
||||
string="Product Variant"
|
||||
name="group_product"
|
||||
icon="terp-product"
|
||||
context="{'group_by': 'product_variant_id'}"/>
|
||||
context="{'group_by': 'product_variant_id'}"
|
||||
/>
|
||||
</search>
|
||||
</field>
|
||||
</record>
|
||||
@@ -124,13 +145,15 @@
|
||||
id="agreement_serviceprofiles"
|
||||
parent="agreement_legal.agreement_masterdata"
|
||||
sequence="50"
|
||||
action="agreement_serviceprofile_action"/>
|
||||
action="agreement_serviceprofile_action"
|
||||
/>
|
||||
|
||||
<menuitem
|
||||
name="Service Profiles"
|
||||
id="dashboard_serviceprofiles"
|
||||
parent="agreement_legal.agreement_dashboard"
|
||||
sequence="20"
|
||||
action="agreement_serviceprofile_dashboard"/>
|
||||
action="agreement_serviceprofile_dashboard"
|
||||
/>
|
||||
|
||||
</odoo>
|
||||
|
||||
Reference in New Issue
Block a user