bemade_fsm: Convert task_template.equipment_id to a Many2many field. Fixes #58.
This commit is contained in:
parent
2b85408e8d
commit
843cc938d1
8 changed files with 52 additions and 25 deletions
|
|
@ -35,7 +35,6 @@ class Equipment(models.Model):
|
|||
|
||||
tag_ids = fields.Many2many('bemade_fsm.equipment.tag',
|
||||
string='Application',
|
||||
tracking=True,
|
||||
help="Classify and analyze your equipment categories like: Boiler, Laboratory, "
|
||||
"Waste water, Pure water")
|
||||
partner_id = fields.Many2one('res.partner',
|
||||
|
|
|
|||
|
|
@ -114,8 +114,8 @@ class SaleOrderLine(models.Model):
|
|||
vals['user_ids'] = template.assignees.ids
|
||||
vals['tag_ids'] = template.tags.ids
|
||||
vals['planned_hours'] = template.planned_hours
|
||||
if template.equipment_id:
|
||||
vals['equipment_ids'] = [Command.set([template.equipment_id.id])]
|
||||
if template.equipment_ids:
|
||||
vals['equipment_ids'] = [Command.set(template.equipment_ids.ids)]
|
||||
return vals
|
||||
|
||||
tmpl = self.product_id.task_template_id
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
from odoo import models, fields, api, _
|
||||
from odoo import models, fields, api, _, Command
|
||||
|
||||
|
||||
class TaskTemplate(models.Model):
|
||||
|
|
@ -24,7 +24,11 @@ class TaskTemplate(models.Model):
|
|||
sequence = fields.Integer(string="Sequence")
|
||||
company_id = fields.Many2one("res.company", string="Company", index=1, default=_current_company)
|
||||
planned_hours = fields.Float("Initially Planned Hours")
|
||||
equipment_id = fields.Many2one(comodel_name="bemade_fsm.equipment", string="Equipment", )
|
||||
equipment_ids = fields.Many2many(comodel_name="bemade_fsm.equipment",
|
||||
relation="bemade_fsm_task_template_equipment_rel",
|
||||
column1="task_template_id",
|
||||
column2="equipment_id",
|
||||
string="Equipment to Service",)
|
||||
|
||||
def action_open_task(self):
|
||||
return {
|
||||
|
|
@ -34,3 +38,9 @@ class TaskTemplate(models.Model):
|
|||
'type': 'ir.actions.act_window',
|
||||
'context': self._context
|
||||
}
|
||||
|
||||
@api.onchange('customer')
|
||||
def _onchange_customer(self):
|
||||
for rec in self:
|
||||
new_equipment_ids = [eq.id for eq in rec.equipment_ids if eq.partner_location_id == rec.customer]
|
||||
rec.write({'equipment_ids': [Command.set(new_equipment_ids)]})
|
||||
|
|
|
|||
|
|
@ -149,7 +149,7 @@ class BemadeFSMBaseTest(TransactionCase):
|
|||
'name': name,
|
||||
'parent': parent and parent.id or False,
|
||||
'planned_hours': planned_hours,
|
||||
'equipment_id': equipment and equipment.id or False,
|
||||
'equipment_ids': [Command.set(equipment and [equipment.id] or [])],
|
||||
})
|
||||
parent = template
|
||||
while structure:
|
||||
|
|
|
|||
|
|
@ -7,18 +7,18 @@ from odoo.exceptions import MissingError
|
|||
@tagged("-at_install", "post_install")
|
||||
class TestEquipment(BemadeFSMBaseTest):
|
||||
def test_crud(self):
|
||||
self.partner_company = self._generate_partner()
|
||||
self.partner_contact = self._generate_partner('Site Contact', 'person', self.partner_company)
|
||||
self.equipment = self._generate_equipment('Test Equipment 1', self.partner_company)
|
||||
partner_company = self._generate_partner()
|
||||
partner_contact = self._generate_partner('Site Contact', 'person', partner_company)
|
||||
equipment = self._generate_equipment('Test Equipment 1', partner_company)
|
||||
|
||||
# Just make sure the basic ORM stuff is OK
|
||||
self.assertTrue(self.equipment in self.partner_company.equipment_ids)
|
||||
self.assertTrue(len(self.partner_company.equipment_ids) == 1)
|
||||
self.assertTrue(equipment in partner_company.equipment_ids)
|
||||
self.assertTrue(len(partner_company.equipment_ids) == 1)
|
||||
|
||||
# Delete should cascade
|
||||
self.partner_company.write({'equipment_ids': [Command.set([])]})
|
||||
partner_company.write({'equipment_ids': [Command.set([])]})
|
||||
with self.assertRaises(MissingError):
|
||||
self.equipment.name
|
||||
equipment.name
|
||||
|
||||
|
||||
@tagged('-at_install', 'post_install', 'slow')
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
from .test_task_template import TestTaskTemplateCommon
|
||||
from .test_task_template import BemadeFSMBaseTest
|
||||
from odoo.tests.common import tagged, HttpCase, Form
|
||||
from odoo import Command
|
||||
|
||||
|
||||
@tagged("-at_install", "post_install")
|
||||
class TestSalesOrder(TestTaskTemplateCommon):
|
||||
class TestSalesOrder(BemadeFSMBaseTest):
|
||||
@tagged('-at_install', 'post_install')
|
||||
def test_order_confirmation_simple_template(self):
|
||||
""" Confirming the order should create a task in the global project based on the task template. """
|
||||
|
|
@ -24,20 +24,23 @@ class TestSalesOrder(TestTaskTemplateCommon):
|
|||
def test_order_confirmation_tree_template(self):
|
||||
partner = self._generate_partner()
|
||||
so = self._generate_sale_order(partner=partner)
|
||||
task_template = self._generate_task_template(structure=[2, 1],
|
||||
names=['Parent Template', 'Child Template',
|
||||
'Grandchild Template'])
|
||||
product = self._generate_product(task_template=task_template)
|
||||
parent_task = self._generate_task_template(structure=[2, 1],
|
||||
names=['Parent Template', 'Child Template',
|
||||
'Grandchild Template'])
|
||||
child_task_1 = parent_task.subtasks[0]
|
||||
child_task_2 = parent_task.subtasks[1]
|
||||
grandchild_task = parent_task.subtasks[0].subtasks[0]
|
||||
product = self._generate_product(task_template=parent_task)
|
||||
sol = self._generate_sale_order_line(so, product=product)
|
||||
|
||||
so.action_confirm()
|
||||
|
||||
self.assertTrue(sol.task_id.child_ids and len(sol.task_id.child_ids) == 2)
|
||||
self.assertTrue(self.parent_task.name in sol.task_id.name)
|
||||
self.assertTrue(self.child_task_1.name in sol.task_id.child_ids[0].name)
|
||||
self.assertTrue(self.child_task_2.name in sol.task_id.child_ids[1].name)
|
||||
self.assertTrue(parent_task.name in sol.task_id.name)
|
||||
self.assertTrue(child_task_1.name in sol.task_id.child_ids[0].name)
|
||||
self.assertTrue(child_task_2.name in sol.task_id.child_ids[1].name)
|
||||
self.assertTrue(sol.task_id.child_ids[0].child_ids and len(sol.task_id.child_ids[0].child_ids) == 1)
|
||||
self.assertTrue(self.grandchild_task.name in sol.task_id.child_ids.child_ids[0].name)
|
||||
self.assertTrue(grandchild_task.name in sol.task_id.child_ids.child_ids[0].name)
|
||||
|
||||
def test_order_confirmation_equipment(self):
|
||||
""" The equipment selected on the SO should transfer to the task."""
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
from .test_bemade_fsm_common import BemadeFSMBaseTest
|
||||
from odoo.tests.common import HttpCase, tagged
|
||||
from odoo.tests.common import HttpCase, tagged, Form
|
||||
from odoo.exceptions import MissingError
|
||||
from odoo import Command
|
||||
from psycopg2.errors import ForeignKeyViolation
|
||||
|
|
@ -57,6 +57,19 @@ class TestTaskTemplate(TestTaskTemplateCommon):
|
|||
with self.assertRaises(MissingError):
|
||||
test = self.grandchild_task.name
|
||||
|
||||
def test_dissociating_customer_resets_equipment_appropriately(self):
|
||||
partner1 = self._generate_partner()
|
||||
partner2 = self._generate_partner()
|
||||
equipment1 = self._generate_equipment(partner=partner1)
|
||||
form = Form(self.task1)
|
||||
form.customer = partner1
|
||||
form.equipment_ids.add(equipment1)
|
||||
|
||||
# Switching the partner should trigger on_change that makes sure equipments are linked to the new partner
|
||||
form.customer = partner2
|
||||
|
||||
self.assertFalse(equipment1 in self.task1.equipment_ids)
|
||||
|
||||
|
||||
@tagged('-at_install', 'post_install', 'slow')
|
||||
class TestTaskTemplateTour(HttpCase, TestTaskTemplateCommon):
|
||||
|
|
|
|||
|
|
@ -23,7 +23,9 @@
|
|||
</group>
|
||||
<group>
|
||||
<field name="customer"/>
|
||||
<field name="equipment_id" domain="[('partner_location_id', '=', customer)]"/>
|
||||
<field name="equipment_ids"
|
||||
domain="[('partner_location_id', '=', customer)]"
|
||||
context="{'tree_view_ref': 'bemade_fsm.equipment_view_tree'}"/>
|
||||
<field name="tags" widget="many2many_tags"/>
|
||||
<field name="company_id" />
|
||||
</group>
|
||||
|
|
|
|||
Loading…
Reference in a new issue