bemade_fsm: Renamed button Mark Done on FSM tasks to Mark as Delivered. Wrote tests to address manager vs user cases for the button. Re #55.

This commit is contained in:
Marc Durepos 2023-07-05 13:48:57 -04:00
parent 74e95be281
commit a847f7e9ef
7 changed files with 91 additions and 18 deletions

View file

@ -50,6 +50,7 @@
'web.assets_tests': [
'bemade_fsm/static/tests/tours/task_template_tour.js',
'bemade_fsm/static/tests/tours/equipment_tour.js',
'bemade_fsm/static/tests/tours/sale_order_tour.js',
],
},
'installable': True,

View file

@ -0,0 +1,40 @@
/** @odoo-module **/
import tour from 'web_tour.tour';
const SO_NAME = "TEST ORDER 2"
const PRODUCT_NAME = "Test Product 3"
tour.register('sale_order_tour', {
test: true,
url: '/web',
},
[tour.stepUtils.showAppsMenuItem(), {
content: 'Navigate to the Service menu',
trigger: '.o_app[data-menu-xmlid="sale.sale_menu_root"]',
}, {
content: 'Search for the sales order',
trigger: 'input.o_searchview_input',
run: `text ${SO_NAME}`,
}, {
content: 'Validate Search',
trigger: '.o_menu_item.o_selection_focus',
run: 'click',
}, {
content: 'Open the test order',
trigger: `.o_data_cell[name="client_order_ref"]:contains(${SO_NAME})`,
}, {
content: 'Click the view tasks button',
trigger: 'button[name="action_view_task"]',
}, {
content: 'Click the first task',
trigger: `div.o_kanban_record:has(span:contains(${PRODUCT_NAME}))`,
}, {
content: 'Click on the ready to invoice button',
trigger: 'button[name="action_fsm_validate"]',
extra_trigger: `li.breadcrumb-item.active:has(span:contains(${PRODUCT_NAME}))`
}, {
content: 'View the SO',
trigger: 'button[name="action_view_so"]',
extra_trigger: 'button[title="Current state"]:contains(Done)',
}
]);

View file

@ -37,3 +37,13 @@ class FSMManagerUserTransactionCase(TransactionCase):
'signature': 'Mr. PM',
'groups_id': [Command.set(group_ids)],
})
group_ids.remove(user_group_fsm_manager.id)
group_ids.remove(user_group_project_manager.id)
cls.user_limited = Users.create({
'name': 'Project User',
'login': 'mruser',
'password': 'mruser',
'email': 'mruser@testco.com',
'signature': 'Mr. User',
'groups_id': [Command.set(group_ids)]
})

View file

@ -1,6 +1,5 @@
from .test_task_template import TestTaskTemplateCommon
from .test_equipment import TestEquipmentCommon
from odoo.tests.common import tagged
from odoo.tests.common import tagged, HttpCase
@tagged("-at_install", "post_install")
@ -13,7 +12,7 @@ class TestSalesOrder(TestTaskTemplateCommon):
})
cls.sale_order1 = cls.env['sale.order'].create({
'partner_id': cls.partner.id,
'client_order_ref': 'TEST ORDER',
'client_order_ref': 'TEST ORDER 1',
'state': 'draft',
})
cls.sol_serv_order = cls.env['sale.order.line'].create({
@ -36,7 +35,7 @@ class TestSalesOrder(TestTaskTemplateCommon):
})
cls.sale_order2 = cls.env['sale.order'].create({
'partner_id': cls.partner.id,
'client_order_ref': 'TEST ORDER',
'client_order_ref': 'TEST ORDER 2',
'state': 'draft',
})
cls.sol_tree_order = cls.env['sale.order.line'].create({
@ -103,11 +102,31 @@ class TestSalesOrder(TestTaskTemplateCommon):
so.action_confirm()
sol = so.order_line[0]
parent_task = sol.task_id
child_task = parent_task.child_ids[0]
child_task = parent_task.child_ids[0]
# Marking the top-level tasks done should set the delivered quantity to some non-zero value based on the UOM
parent_task.action_fsm_validate()
sol._compute_qty_delivered()
# sol._compute_qty_delivered()
self.assertTrue(sol.qty_delivered != 0)
# Marking a child task done should not create a sale order
child_task.action_fsm_validate()
self.assertFalse(child_task.sale_order_id)
self.assertFalse(child_task.sale_order_id)
@tagged("-at_install", "post_install", 'focus')
class TestSaleOrderTour(HttpCase, TestSalesOrder):
def test_sale_order_tour_no_invoice_button_for_non_manager(self):
# Make sure a non-manager cannot mark a task as ready to invoice
so = self.sale_order2
so.action_confirm()
with self.assertRaises(AssertionError) as e:
self.start_tour('/web', 'sale_order_tour',
login='mruser', )
self.assertTrue("Click on the ready to invoice button" in str(e.exception))
def test_task_mark_to_invoice(self):
# Make sure that when a manager clicks the ready to invoice button, the qty delivered is updated on the SO
so = self.sale_order2
so.action_confirm()
sol = so.order_line.filtered(lambda l: 'Test Product 3' in l.name)
self.start_tour('/web', 'sale_order_tour', login='misterpm')
self.assertTrue(sol.qty_delivered != 0)

View file

@ -1,8 +1,9 @@
from .test_sale_order import TestSalesOrder
from odoo import Command
from odoo.tests.common import Form
from odoo.tests.common import Form, tagged
@tagged("-at_install", "post_install")
class TestSaleOrderTaskContacts(TestSalesOrder):
@classmethod
def setUpClass(cls):

View file

@ -18,15 +18,9 @@ class TestTaskTemplateCommon(FSMManagerUserTransactionCase):
'name': 'Template 1',
})
cls.project = cls.env['project.project'].create({
'name': 'Test Project',
'allow_material': True,
'allow_timesheets': True,
'allow_subtasks': True,
'allow_quotations': True,
'allow_worksheets': True,
'is_fsm': True,
})
cls.project = cls.env.ref('industry_fsm.fsm_project')
cls.project.write({'allow_subtasks': True,})
cls.product_task_global_project = cls.env['product.product'].create({
'name': 'Test Product 1',
'type': 'service',

View file

@ -4,7 +4,7 @@
<record id="bemade_fsm_project_task_form_inherit" model="ir.ui.view">
<field name="name">bemade_fsm.project_task.form</field>
<field name="model">project.task</field>
<field name="inherit_id" ref="project.view_task_form2"/>
<field name="inherit_id" ref="industry_fsm.view_task_form2_inherit"/>
<field name="priority" eval="8"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='partner_id']" position="after">
@ -20,6 +20,14 @@
</group>
</page>
</xpath>
<button name="action_fsm_validate" class='btn-primary' position="attributes">
<attribute name="string">Mark as Delivered</attribute>
<attribute name="groups">industry_fsm.group_fsm_manager</attribute>
</button>
<button name="action_fsm_validate" class='btn-secondary' position="attributes">
<attribute name="string">Mark as Delivered</attribute>
<attribute name="groups">industry_fsm.group_fsm_manager</attribute>
</button>
</field>
</record>
<!-- Add parent_id = false to domain for My Tasks, All Tasks: To Schedule, All Tasks and To Invoice-->