| 1 |
import { registry } from "@web/core/registry"; |
| 2 |
import { assert } from "@stock/../tests/tours/tour_helper"; |
| 3 |
import { catalogSuggestion } from "./tour_helper"; |
| 4 |
import { purchaseForm, productCatalog } from "@purchase/../tests/tours/tour_helper"; |
| 5 |
|
| 6 |
registry.category("web_tour.tours").add("test_purchase_order_suggest_search_panel_ux", { |
| 7 |
steps: () => [ |
| 8 |
/* |
| 9 |
* ----------------- PART 1 : Suggest Component ----------------- |
| 10 |
* Checks that the Suggest UI in the search panel works well |
| 11 |
* (estimated price, warehouse logic, toggling, saving defaults) |
| 12 |
* ---------------------------------------------------------------- |
| 13 |
*/ |
| 14 |
{ trigger: ".o_purchase_order" }, |
| 15 |
...purchaseForm.createNewPO(), |
| 16 |
...purchaseForm.selectVendor("Test Vendor"), |
| 17 |
...purchaseForm.selectWarehouse("Other Warehouse: Receipts"), |
| 18 |
...purchaseForm.openCatalog(), |
| 19 |
{ |
| 20 |
content: "Checks suggest is off by default and suggest fields hidden when suggest off", |
| 21 |
trigger: ".o_kanban_view.o_purchase_product_kanban_catalog_view", |
| 22 |
run() { |
| 23 |
const els = document.querySelectorAll( |
| 24 |
".o_TimePeriodSelectionField, input.o_PurchaseSuggestInput, .o_purchase_suggest_footer" |
| 25 |
); |
| 26 |
assert(els.length, 0, "Toggle did not hide elements"); |
| 27 |
}, |
| 28 |
}, |
| 29 |
|
| 30 |
// --- Check that suggestion feature does not appear on non draft POs --- |
| 31 |
...productCatalog.goBackToOrder(), |
| 32 |
{ trigger: ".o_purchase_order" }, |
| 33 |
{ |
| 34 |
content: "Confirm PO", |
| 35 |
trigger: 'button[name="button_confirm"]', |
| 36 |
run: "click", |
| 37 |
}, |
| 38 |
...purchaseForm.openCatalog(), |
| 39 |
{ trigger: 'body:not(:has(div[name="search_panel_suggestion"]))' }, // Suggest should not show on non draft POs |
| 40 |
...productCatalog.goBackToOrder(), |
| 41 |
{ |
| 42 |
content: "Cancel PO", |
| 43 |
trigger: 'button[name="button_cancel"]', |
| 44 |
run: "click", |
| 45 |
}, |
| 46 |
{ |
| 47 |
content: "Reset to draft", |
| 48 |
trigger: 'button[name="button_draft"]', |
| 49 |
run: "click", |
| 50 |
}, |
| 51 |
...purchaseForm.openCatalog(), |
| 52 |
|
| 53 |
// --- Check suggestion uses PO warehouse (this WH only has 1 delivery) --- |
| 54 |
...catalogSuggestion.toggleSuggest(true), |
| 55 |
{ |
| 56 |
content: "Toggling Suggestion activates filter for products in PO or suggested", |
| 57 |
trigger: '.o_facet_value:contains("Suggested")', // Suggested |
| 58 |
}, |
| 59 |
...catalogSuggestion.setParameters({ basedOn: "Last 3 months", nbDays: 90, factor: 100 }), |
| 60 |
{ trigger: "span[name='suggest_total']:visible:contains('$ 20.00')" }, |
| 61 |
...productCatalog.goBackToOrder(), |
| 62 |
...purchaseForm.selectWarehouse("Inventory Test Company: Receipts"), |
| 63 |
...purchaseForm.openCatalog(), |
| 64 |
...catalogSuggestion.setParameters({ basedOn: "Last 7 days", nbDays: 28, factor: 50 }), |
| 65 |
{ trigger: "span[name='suggest_total']:visible:contains('$ 480.00')" }, // 12 units/week * 4 weeks * 20$/ unit * 50% = 480$ |
| 66 |
|
| 67 |
// --- Check Add All: suggest qty added and suggest parameters are saved on vendor |
| 68 |
...catalogSuggestion.addAllSuggestions(), |
| 69 |
...productCatalog.goBackToOrder(), |
| 70 |
...purchaseForm.checkLineValues(0, { product: "test_product", quantity: "24.00" }), |
| 71 |
...purchaseForm.createNewPO(), |
| 72 |
...purchaseForm.selectVendor("Test Vendor"), |
| 73 |
...purchaseForm.selectWarehouse("Inventory Test Company: Receipts"), |
| 74 |
...purchaseForm.openCatalog(), |
| 75 |
...catalogSuggestion.assertParameters({ basedOn: "Last 7 days", nbDays: 28, factor: 50 }), |
| 76 |
/* |
| 77 |
* ----------------- PART 2 : Kanban Interactions ----------------- |
| 78 |
* Checks the Suggest UI and the Kanban record interactions |
| 79 |
* (monthly demand, suggested_qty, forecasted + record ordering) |
| 80 |
* ------------------------------------------------------------------ |
| 81 |
*/ |
| 82 |
...catalogSuggestion.setParameters({ basedOn: "Last 7 days", nbDays: 28, factor: 50 }), // 1 order of 12 used in computation of demand // 28 days --> forecast uses both 50 delivery |
| 83 |
{ trigger: "span[name='suggest_total']:visible:contains('480')" }, |
| 84 |
...catalogSuggestion.assertCatalogRecord("test_product", { monthly: 52, suggest: 24, forecast: 100 }), |
| 85 |
...catalogSuggestion.checkKanbanRecordPosition("test_product", 0), |
| 86 |
|
| 87 |
...catalogSuggestion.setParameters({ basedOn: "Last 30 days", factor: 10 }), // 2 orders of 12 |
| 88 |
{ trigger: "span[name='suggest_total']:visible:contains('60')" }, |
| 89 |
...catalogSuggestion.assertCatalogRecord("test_product", { monthly: 24, suggest: 3 }), |
| 90 |
|
| 91 |
...catalogSuggestion.setParameters({ basedOn: "Last 3 months", factor: 500 }), // 2 orders of 12 |
| 92 |
{ trigger: "span[name='suggest_total']:visible:contains('740')" }, |
| 93 |
...catalogSuggestion.assertCatalogRecord("test_product", { monthly: 8, suggest: 37 }), |
| 94 |
|
| 95 |
// --- Check with Forecasted quantities |
| 96 |
...catalogSuggestion.setParameters({ basedOn: "Forecasted", nbDays: 18, factor: 100 }), |
| 97 |
{ trigger: "span[name='suggest_total']:visible:contains('1,000')" }, |
| 98 |
...catalogSuggestion.assertCatalogRecord("test_product", { forecast: 50, suggest: 50 }), // 18 days --> forecast uses only one 50 delivery |
| 99 |
|
| 100 |
...catalogSuggestion.setParameters({ nbDays: 7 }), |
| 101 |
{ trigger: "span[name='suggest_total']:visible:contains('$ 0.00')" }, // Move out of 100 in 20days, so no suggest for 7 days |
| 102 |
{ trigger: ".o_view_nocontent_smiling_face" }, // Should suggest no products |
| 103 |
|
| 104 |
// --- Check with suggest OFF we come back to normal |
| 105 |
...catalogSuggestion.toggleSuggest(false), |
| 106 |
...catalogSuggestion.assertCatalogRecord("test_product", { forecast: 100, monthly: 24 }), |
| 107 |
...catalogSuggestion.checkKanbanRecordPosition("Other product", 0), |
| 108 |
{ trigger: "span[name='kanban_monthly_demand_qty']:visible:contains('24')" }, // Should come back to normal monthly demand |
| 109 |
|
| 110 |
/* |
| 111 |
* ------------------- PART 3 : KANBAN FILTERS --------------------- |
| 112 |
* Checks suggest and searchModel (filters) interactions |
| 113 |
* (Add / Remove with filters), category filters |
| 114 |
* ------------------------------------------------------------------ |
| 115 |
*/ |
| 116 |
|
| 117 |
// ---- Check Adding non suggested product works with suggest |
| 118 |
...productCatalog.addProduct("Other product"), |
| 119 |
...productCatalog.waitForQuantity("Other product", 1), |
| 120 |
...catalogSuggestion.toggleSuggest(true), |
| 121 |
|
| 122 |
// ---- Check toggling suggest OFF with filters manually removed still works |
| 123 |
...catalogSuggestion.removeSuggestFilter(), |
| 124 |
...catalogSuggestion.toggleSuggest(false), |
| 125 |
...catalogSuggestion.checkKanbanRecordPosition("Other product", 0), // == suggest is off |
| 126 |
|
| 127 |
// --- Turning suggest on with non suggested product works as expected |
| 128 |
// Because Add product can be slow to reach server and because when toggling suggest we filter |
| 129 |
// products in the order, we go back to catalog and come back (similar to an await). |
| 130 |
// (This will probably not be need in following PR when we remove debounce on AddProduct) |
| 131 |
...productCatalog.goBackToOrder(), |
| 132 |
...purchaseForm.openCatalog(), |
| 133 |
...catalogSuggestion.toggleSuggest(true), |
| 134 |
...catalogSuggestion.checkKanbanRecordPosition("Other product", 1), // Other product still shown because in order but after suggested products |
| 135 |
|
| 136 |
// Check that categories work well with suggestions |
| 137 |
...productCatalog.selectSearchPanelCategory("Goods"), |
| 138 |
{ trigger: "span[name='suggest_total']:visible:contains('$ 0.00')" }, // Should recompute estimated price |
| 139 |
...productCatalog.selectSearchPanelCategory("Test Category"), |
| 140 |
{ trigger: "span[name='suggest_total']:visible:contains('$ 480.00')" }, |
| 141 |
...catalogSuggestion.removeSuggestFilter(), // Shouldn't impact categories |
| 142 |
{ trigger: "span[name='suggest_total']:visible:contains('$ 480.00')" }, |
| 143 |
|
| 144 |
// ---- Finally done :) |
| 145 |
...productCatalog.goBackToOrder(), |
| 146 |
{ |
| 147 |
content: "Go back to the dashboard", |
| 148 |
trigger: ".o_menu_brand", |
| 149 |
run: "click", |
| 150 |
}, |
| 151 |
], |
| 152 |
}); |