| 1 |
import { assert } from "@stock/../tests/tours/tour_helper"; |
| 2 |
|
| 3 |
export const catalogSuggestion = { |
| 4 |
/** |
| 5 |
* Sets the Suggest UI parameters. |
| 6 |
* @param {string} [basedOn] The label value of the "Replenish based on" select options (eg. "Last 3 months") |
| 7 |
* @param {number} [nbDays] The value of the "Replenish for" input (eg. 90) |
| 8 |
* @param {number} [factor] The value of the "x ...%" input (eg. 50) |
| 9 |
*/ |
| 10 |
setParameters({ basedOn = false, nbDays = false, factor = false }) { |
| 11 |
const steps = []; |
| 12 |
if (nbDays) { |
| 13 |
steps.push({ |
| 14 |
trigger: "input.o_PurchaseSuggestInput:eq(0)", |
| 15 |
run: `edit ${nbDays}`, |
| 16 |
}); |
| 17 |
} |
| 18 |
if (factor) { |
| 19 |
steps.push({ |
| 20 |
trigger: "input.o_PurchaseSuggestInput:eq(1)", |
| 21 |
run: `edit ${factor}`, |
| 22 |
}); |
| 23 |
} |
| 24 |
// Little trick to add the the basedOn step last because it doesn't have a debounce |
| 25 |
// meaning it will trigger a kanbanReload with the params above already set. |
| 26 |
if (basedOn) { |
| 27 |
steps.push( |
| 28 |
{ |
| 29 |
trigger: ".o_TimePeriodSelectionField .o_select_menu .dropdown-toggle:visible", |
| 30 |
run: "click", |
| 31 |
}, |
| 32 |
{ |
| 33 |
trigger: ".o_select_menu_menu:visible", |
| 34 |
}, |
| 35 |
{ |
| 36 |
trigger: `.o_select_menu_menu .o_select_menu_item:contains('${basedOn}'):visible`, |
| 37 |
run: "click", |
| 38 |
} |
| 39 |
); |
| 40 |
} |
| 41 |
return steps; |
| 42 |
}, |
| 43 |
|
| 44 |
/** |
| 45 |
* Asserts the Suggest UI parameters are saved as expected. |
| 46 |
* @param {string} [basedOn] The label value of the "Replenish based on" select options (eg. "Last 3 months") |
| 47 |
* @param {number} [nbDays] The value of the "Replenish for" input (eg. 90) |
| 48 |
* @param {number} [factor] The value of the "x ...%" input (eg. 50) |
| 49 |
*/ |
| 50 |
assertParameters({ basedOn = false, nbDays = false, factor = false }) { |
| 51 |
const steps = []; |
| 52 |
|
| 53 |
if (nbDays) { |
| 54 |
steps.push({ |
| 55 |
content: "Check number days saved", |
| 56 |
trigger: "input.o_PurchaseSuggestInput:eq(0)", |
| 57 |
run() { |
| 58 |
const days = parseInt(this.anchor.value, 10); |
| 59 |
assert(days, nbDays, `Expected days ${nbDays}, got ${days}`); |
| 60 |
}, |
| 61 |
}); |
| 62 |
} |
| 63 |
if (factor) { |
| 64 |
steps.push({ |
| 65 |
content: "Check percent factor saved", |
| 66 |
trigger: "input.o_PurchaseSuggestInput:eq(1)", |
| 67 |
run() { |
| 68 |
const percent = parseInt(this.anchor.value, 10); |
| 69 |
assert(percent, factor, `Expected percent factor ${factor}, got ${percent}`); |
| 70 |
}, |
| 71 |
}); |
| 72 |
} |
| 73 |
if (basedOn) { |
| 74 |
steps.push({ |
| 75 |
content: "Check based-on saved", |
| 76 |
trigger: ".o_TimePeriodSelectionField", |
| 77 |
run() { |
| 78 |
const drop = this.anchor.querySelector(".o_select_menu_toggler"); |
| 79 |
assert(drop.value, basedOn, `Expected based on ${basedOn}, got ${drop.value}`); |
| 80 |
}, |
| 81 |
}); |
| 82 |
} |
| 83 |
|
| 84 |
return steps; |
| 85 |
}, |
| 86 |
|
| 87 |
/** |
| 88 |
* Checks catalog kanban record fields match expectations |
| 89 |
* @param {string} productName The product display name of the card to check |
| 90 |
* @param {number} [monthly] The product monthly demand |
| 91 |
* @param {number} [suggest] The product suggested quantity |
| 92 |
* @param {number} [forecast] The product forecasted quantity |
| 93 |
*/ |
| 94 |
assertCatalogRecord(productName, { monthly, suggest, forecast } = {}) { |
| 95 |
const steps = []; |
| 96 |
if (monthly) { |
| 97 |
steps.push({ |
| 98 |
content: `Check catalog record monthly demand for product ${productName}`, |
| 99 |
trigger: `.o_kanban_record:contains('${productName}') span[name='kanban_monthly_demand_qty']:visible:contains('${monthly}')`, |
| 100 |
}); |
| 101 |
} |
| 102 |
if (suggest) { |
| 103 |
steps.push({ |
| 104 |
content: `Check catalog record suggested quantity for product ${productName}`, |
| 105 |
trigger: `.o_kanban_record:contains('${productName}') div[name='kanban_purchase_suggest'] span:visible:contains('${suggest}')`, |
| 106 |
}); |
| 107 |
} |
| 108 |
if (forecast) { |
| 109 |
steps.push({ |
| 110 |
content: `Check catalog record forecasted quantity for product ${productName}`, |
| 111 |
trigger: `.o_kanban_record:contains('${productName}') span[name='o_kanban_forecasted_qty']:visible:contains('${forecast}')`, |
| 112 |
}); |
| 113 |
} |
| 114 |
return steps; |
| 115 |
}, |
| 116 |
|
| 117 |
/** |
| 118 |
* @param {boolean} turnOn True to turn Suggest ON, false to turn it OFF |
| 119 |
*/ |
| 120 |
toggleSuggest(turnOn) { |
| 121 |
return [ |
| 122 |
{ |
| 123 |
trigger: 'div[name="search-suggest-toggle"] input', |
| 124 |
run: "click", |
| 125 |
}, |
| 126 |
{ |
| 127 |
trigger: `div[name="search-suggest-toggle"] input:${ |
| 128 |
turnOn ? "checked" : "not(:checked)" |
| 129 |
}`, |
| 130 |
}, |
| 131 |
]; |
| 132 |
}, |
| 133 |
|
| 134 |
/** |
| 135 |
* Checks a product's record order in Kanban |
| 136 |
* @param {string} product product display name |
| 137 |
* @param {number } expectedOrder 0 is the first card |
| 138 |
*/ |
| 139 |
checkKanbanRecordPosition(product, expectedOrder) { |
| 140 |
const trigger = `.o_purchase_product_kanban_catalog_view article.o_kanban_record:nth-child(${expectedOrder + 1}):contains("${product}")`; |
| 141 |
return [{ trigger }]; |
| 142 |
}, |
| 143 |
|
| 144 |
removeSuggestFilter() { |
| 145 |
const content = "Remove the Suggested filter"; |
| 146 |
const trigger = '.o_facet_value:contains("Suggested")'; |
| 147 |
const run = async (actions) => { |
| 148 |
const filters = [...document.querySelectorAll(".o_searchview_facet")]; |
| 149 |
const suggestedFilter = filters.find((el) => el.textContent.includes("Suggested")); |
| 150 |
await actions.click(suggestedFilter.querySelector(".o_facet_remove")); |
| 151 |
}; |
| 152 |
return [{ content, trigger, run }]; |
| 153 |
}, |
| 154 |
|
| 155 |
addAllSuggestions() { |
| 156 |
const content = "Add all suggestion to the PO"; |
| 157 |
const trigger = 'button[name="suggest_add_all"]'; |
| 158 |
return [{ content, trigger, run: "click" }]; |
| 159 |
}, |
| 160 |
}; |