bemade_fsm: Site contacts and work order contacts added and unit tested. Need to do the UI and integration testing next. Re #37.
This commit is contained in:
parent
71ad597133
commit
31528dbdc6
11 changed files with 108 additions and 28 deletions
|
|
@ -35,6 +35,7 @@
|
|||
'industry_fsm',
|
||||
'industry_fsm_sale',
|
||||
'bemade_partner_root_ancestor',
|
||||
'mail',
|
||||
],
|
||||
'data': ['views/task_template_views.xml',
|
||||
'views/equipment.xml',
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ class EquipmentType(models.Model):
|
|||
|
||||
name = fields.Char(string='Intervention Name', required=True, translate=True)
|
||||
|
||||
|
||||
class Equipment(models.Model):
|
||||
_name = 'bemade_fsm.equipment'
|
||||
_rec_name = 'complete_name'
|
||||
|
|
@ -39,13 +40,14 @@ class Equipment(models.Model):
|
|||
"Waste water, Pure water")
|
||||
partner_id = fields.Many2one('res.partner',
|
||||
string="Owner",
|
||||
compute="_compute_partner")
|
||||
compute="_compute_partner",
|
||||
search="_search_partner", )
|
||||
description = fields.Text(string="Description",
|
||||
tracking=True)
|
||||
|
||||
partner_location_id = fields.Many2one('res.partner',
|
||||
string="Physical Address",
|
||||
tracking=True,)
|
||||
tracking=True, )
|
||||
|
||||
location_notes = fields.Text(string="Physical Location Notes",
|
||||
tracking=True)
|
||||
|
|
@ -58,6 +60,10 @@ class Equipment(models.Model):
|
|||
for rec in self:
|
||||
rec.partner_id = rec.partner_location_id and rec.partner_location_id.root_ancestor
|
||||
|
||||
@api.model
|
||||
def _search_partner(self, operator, value):
|
||||
return [('partner_location_id.root_ancestor', operator, value)]
|
||||
|
||||
@api.depends('pid_tag', 'name')
|
||||
def _compute_complete_name(self):
|
||||
for rec in self:
|
||||
|
|
@ -87,4 +93,4 @@ class Equipment(models.Model):
|
|||
'context': self.env.context,
|
||||
'res_model': 'bemade_fsm.equipment',
|
||||
'type': 'ir.actions.act_window',
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,8 @@ class Partner(models.Model):
|
|||
string='Site Equipment')
|
||||
|
||||
is_site_contact = fields.Boolean(string='Is a site contact',
|
||||
compute="_compute_is_site_contact")
|
||||
compute="_compute_is_site_contact",
|
||||
search="_search_is_site_contact",)
|
||||
|
||||
site_ids = fields.Many2many(string='Work Sites',
|
||||
comodel_name='res.partner',
|
||||
|
|
@ -33,6 +34,14 @@ class Partner(models.Model):
|
|||
domain=[('is_company', '=', False)],
|
||||
tracking=True)
|
||||
|
||||
work_order_contacts = fields.Many2many(string='Work Order Recipients',
|
||||
comodel_name='res.partner',
|
||||
relation='res_partner_work_order_contacts_rel',
|
||||
column1='res_partner_id',
|
||||
column2='work_order_contact_id',
|
||||
domain=[('is_company', '=', False)],
|
||||
tracking=True)
|
||||
|
||||
@api.depends('site_ids')
|
||||
def _compute_is_site_contact(self):
|
||||
for rec in self:
|
||||
|
|
@ -41,5 +50,9 @@ class Partner(models.Model):
|
|||
@api.depends('equipment_ids')
|
||||
def _compute_equipment_count(self):
|
||||
for rec in self:
|
||||
all_equipmemt_ids = self.env['bemade_fsm.equipment'].search([('partner_id', '=', rec.id)])
|
||||
rec.equipment_count = len(all_equipmemt_ids)
|
||||
all_equipment_ids = self.env['bemade_fsm.equipment'].search([('partner_id', '=', rec.id)])
|
||||
rec.equipment_count = len(all_equipment_ids)
|
||||
|
||||
@api.model
|
||||
def _search_is_site_contact(self, operator, value):
|
||||
return [('site_contacts', '!=', False)]
|
||||
|
|
|
|||
|
|
@ -1,6 +1,33 @@
|
|||
from odoo import fields, models, api, _, Command
|
||||
|
||||
|
||||
class SaleOrder(models.Model):
|
||||
_inherit = 'sale.order'
|
||||
|
||||
site_contacts = fields.Many2many(comodel_name='res.partner',
|
||||
relation="sale_order_site_contacts_rel",
|
||||
compute="_compute_default_contacts",
|
||||
inverse="_inverse_default_contacts",
|
||||
string='Site Contacts',
|
||||
store=True)
|
||||
|
||||
work_order_contacts = fields.Many2many(comodel_name='res.partner',
|
||||
relation='sale_order_work_order_contacts_rel',
|
||||
compute='_compute_default_contacts',
|
||||
inverse='_inverse_default_contacts',
|
||||
string='Work Order Recipients',
|
||||
store=True)
|
||||
|
||||
@api.depends('partner_id')
|
||||
def _compute_default_contacts(self):
|
||||
for rec in self:
|
||||
rec.site_contacts = rec.partner_id.site_contacts
|
||||
rec.work_order_contacts = rec.partner_id.work_order_contacts
|
||||
|
||||
def _inverse_default_contacts(self):
|
||||
pass
|
||||
|
||||
|
||||
class SaleOrderLine(models.Model):
|
||||
_inherit = 'sale.order.line'
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ from odoo import models, fields, api, _
|
|||
|
||||
class TaskTemplate(models.Model):
|
||||
_name = 'project.task.template'
|
||||
|
||||
_description = "Template for new project tasks"
|
||||
@api.model
|
||||
def _current_company(self):
|
||||
return self.env.company
|
||||
|
|
|
|||
|
|
@ -2,3 +2,4 @@ from . import test_bemade_fsm_common
|
|||
from . import test_task_template
|
||||
from . import test_task_template_sale_order
|
||||
from . import test_equipment
|
||||
from . import test_fsm_contact_setting
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
from odoo.tests.common import TransactionCase
|
||||
from odoo.tests.common import TransactionCase, tagged
|
||||
from odoo import Command
|
||||
|
||||
|
||||
@tagged("-at_install", "post_install")
|
||||
class FSMManagerUserTransactionCase(TransactionCase):
|
||||
|
||||
@classmethod
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
from odoo.tests.common import HttpCase, tagged
|
||||
from .test_bemade_fsm_common import FSMManagerUserTransactionCase
|
||||
|
||||
|
||||
@tagged("-at_install", "post_install")
|
||||
class TestEquipmentCommon(FSMManagerUserTransactionCase):
|
||||
|
||||
@classmethod
|
||||
|
|
|
|||
|
|
@ -1,30 +1,56 @@
|
|||
from odoo.tests import TransactionCase, HttpCase, tagged
|
||||
from odoo import Command
|
||||
from test_bemade_fsm_common import FSMManagerUserTransactionCase
|
||||
from .test_bemade_fsm_common import FSMManagerUserTransactionCase
|
||||
|
||||
|
||||
@tagged("-at_install", "post_install")
|
||||
class SaleOrderFSMContactsCase(FSMManagerUserTransactionCase):
|
||||
|
||||
def test_default_site_contacts(self):
|
||||
# Make sure the SO pulls the defaults from the partner correctly
|
||||
pass
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
Partner = cls.env['res.partner']
|
||||
cls.parent_co = Partner.create({
|
||||
'name': 'Parent Co',
|
||||
'company_type': 'company',
|
||||
})
|
||||
cls.contact_1 = Partner.create({
|
||||
'name': 'Contact 1',
|
||||
'company_type': 'person',
|
||||
'parent_id': cls.parent_co.id,
|
||||
})
|
||||
cls.contact_2 = Partner.create({
|
||||
'name': 'Contact 2',
|
||||
'company_type': 'person',
|
||||
'parent_id': cls.parent_co.id,
|
||||
})
|
||||
|
||||
def test_default_billing_contacts(self):
|
||||
def test_site_contacts(self):
|
||||
# Make sure the SO pulls the defaults from the partner correctly
|
||||
pass
|
||||
self.parent_co.write({'site_contacts': [Command.set([self.contact_1.id, self.contact_2.id])]})
|
||||
so = self.env['sale.order'].create({
|
||||
'partner_id': self.parent_co.id,
|
||||
})
|
||||
self.assertTrue(so.site_contacts == self.parent_co.site_contacts)
|
||||
# Make sure updating the site contacts on the SO doesn't feed back to the partner
|
||||
so.write({'site_contacts': [Command.set([self.contact_1.id])]})
|
||||
self.assertTrue(self.contact_1 in so.site_contacts)
|
||||
self.assertTrue(self.contact_2 not in so.site_contacts)
|
||||
self.assertTrue(so.site_contacts != so.partner_id.site_contacts and len(so.partner_id.site_contacts) == 2)
|
||||
|
||||
def test_default_workorder_contacts(self):
|
||||
# Make sure the SO pulls the defaults from the partner correctly
|
||||
pass
|
||||
|
||||
def test_change_site_contacts(self):
|
||||
# Make sure the SO contacts can be updated without feeding back to the partner
|
||||
pass
|
||||
|
||||
def test_change_workorder_contacts(self):
|
||||
# Make sure the SO contacts can be updated without feeding back to the partner
|
||||
pass
|
||||
|
||||
def test_change_billing_contacts(self):
|
||||
# Make sure the SO contacts can be updated without feedin back to the partner
|
||||
pass
|
||||
|
||||
self.parent_co.write({'work_order_contacts': [Command.set([self.contact_1.id, self.contact_2.id])]})
|
||||
so = self.env['sale.order'].create({
|
||||
'partner_id': self.parent_co.id,
|
||||
})
|
||||
self.assertTrue(self.contact_1 in self.parent_co.work_order_contacts)
|
||||
self.assertTrue(self.contact_2 in self.parent_co.work_order_contacts)
|
||||
self.assertTrue(self.contact_1 in so.work_order_contacts)
|
||||
self.assertTrue(self.contact_2 in so.work_order_contacts)
|
||||
# Make sure setting the work order contacts on the SO doesn't feed back to the partner
|
||||
so.write({'work_order_contacts': [Command.set([self.contact_1.id])]})
|
||||
self.assertTrue(self.contact_1 in so.work_order_contacts)
|
||||
self.assertTrue(self.contact_2 not in so.work_order_contacts)
|
||||
self.assertTrue(
|
||||
so.work_order_contacts != so.partner_id.work_order_contacts and len(so.partner_id.work_order_contacts) == 2)
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ from odoo import Command
|
|||
from psycopg2.errors import ForeignKeyViolation
|
||||
|
||||
|
||||
@tagged("-at_install", "post_install")
|
||||
class TestTaskTemplateCommon(FSMManagerUserTransactionCase):
|
||||
|
||||
@classmethod
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ from .test_task_template import TestTaskTemplateCommon
|
|||
from odoo.tests.common import tagged
|
||||
|
||||
|
||||
@tagged("-at_install", "post_install")
|
||||
class TestTaskTemplateSalesOrder(TestTaskTemplateCommon):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
|
|
|
|||
Loading…
Reference in a new issue