19.0 vanilla

This commit is contained in:
Ernad Husremovic 2026-03-09 09:32:12 +01:00
parent 79f83631d5
commit 73afc09215
6267 changed files with 1534193 additions and 1130106 deletions

View file

@ -0,0 +1,30 @@
import { models } from '@web/../tests/web_test_helpers';
import { ProductProduct as ProductModel } from './product_product';
export class ProductProduct extends ProductModel {
_records = [
{ id: 1, name: "Black chair", type: 'goods', list_price: 50.0 },
{ id: 2, name: "Blue chair", type: 'goods', list_price: 60.0 },
{ id: 3, name: "Black table", type: 'goods', list_price: 70.0 },
{ id: 4, name: "Blue table", type: 'goods', list_price: 80.0 },
{ id: 5, name: "Test Combo", type: 'combo', combo_ids: [1, 2] },
];
}
export class ProductComboItem extends models.ServerModel {
_name = 'product.combo.item';
_records = [
{ id: 1, product_id: 1 },
{ id: 2, product_id: 2 },
{ id: 3, product_id: 3 },
{ id: 4, product_id: 4 },
];
}
export class ProductCombo extends models.ServerModel {
_name = 'product.combo';
_records = [
{ id: 1, name: "Chair combo", combo_item_ids: [1, 2] },
{ id: 2, name: "Table combo", combo_item_ids: [3, 4] },
];
}

View file

@ -0,0 +1,12 @@
import { models } from "@web/../tests/web_test_helpers";
export class ProductProduct extends models.ServerModel {
_name = "product.product";
_records = [
{id: 1, name: "Test Product", type: "consu", list_price: 20.0},
{id: 2, name: "Test Service Product", type: "service", list_price: 50.0},
{id: 14, name: "desk"},
];
}

View file

@ -0,0 +1,12 @@
import { models } from "@web/../tests/web_test_helpers";
export class ProductTemplate extends models.ServerModel {
_name = "product.template";
get_single_product_variant() {
return { product_id: 14, product_name: "desk" };
}
_records = [{ id: 12, name: "desk" }];
}

View file

@ -0,0 +1,16 @@
import { defineModels } from '@web/../tests/web_test_helpers';
import {
ProductCombo,
ProductComboItem,
ProductProduct,
} from './mock_server/mock_models/product_combo';
export const comboModels = {
ProductCombo,
ProductComboItem,
ProductProduct,
}
export function defineComboModels() {
defineModels(comboModels);
}

View file

@ -0,0 +1,88 @@
import { defineMailModels } from "@mail/../tests/mail_test_helpers";
import { expect, test } from "@odoo/hoot";
import { queryAllTexts } from "@odoo/hoot-dom";
import { contains, defineModels, fields, getService, models, mountWebClient, onRpc } from "@web/../tests/web_test_helpers";
class ProductProduct extends models.Model {
_records = [{ id: 42, name: "Customizable Desk" }];
name = fields.Char();
}
class ProductPricelist extends models.Model {
_records = [
{ id: 1, name: "Public Pricelist" },
{ id: 2, name: "Test" },
];
name = fields.Char();
}
defineModels([ProductProduct, ProductPricelist]);
defineMailModels();
test(`Pricelist Client Action`, async () => {
onRpc("report.product.report_pricelist", "get_html", async () => "");
await mountWebClient();
await getService("action").doAction({
id: 1,
name: "Generate Pricelist Report",
tag: "generate_pricelist_report",
type: "ir.actions.client",
context: {
active_ids: [42],
active_model: "product.product",
},
});
// checking default pricelist
expect(`select#pricelists > option:eq(0)`).toHaveText("Public Pricelist", {
message: "should have default pricelist",
});
// changing pricelist
await contains(`select#pricelists`).select("2");
// check whether pricelist value has been updated or not
expect(`select#pricelists > option:eq(0)`).toHaveText("Test", {
message: "After pricelist change, the pricelist_id field should be updated",
});
// check default quantities should be there
expect(queryAllTexts(`.o_badges_list .badge`)).toEqual(["1", "5", "10"]);
// existing quantity can not be added.
await contains(`.o_add_qty`).click();
expect(queryAllTexts(`.o_badges_list .badge`)).toEqual(["1", "5", "10"]);
expect(`.o_notification`).toHaveCount(1);
expect(`.o_notification .o_notification_content`).toHaveText(
"Quantity already present (1).",
{ message: "Existing Quantity can not be added" }
);
expect(`.o_notification .o_notification_bar`).toHaveClass("bg-info");
await contains(`.o_notification_close`).click();
expect(`.o_notification`).toHaveCount(0);
// adding few more quantities to check.
await contains(`.add-quantity-input`).edit("2", { confirm: false });
await contains(`.o_add_qty`).click();
expect(queryAllTexts(`.o_badges_list .badge`)).toEqual(["1", "2", "5", "10"]);
expect(`.o_notification`).toHaveCount(0);
await contains(`.add-quantity-input`).edit("3", { confirm: false });
await contains(`.o_add_qty`).click();
expect(queryAllTexts(`.o_badges_list .badge`)).toEqual(["1", "2", "3", "5", "10"]);
expect(`.o_notification`).toHaveCount(0);
// no more than 5 quantities can be used at a time
await contains(`.add-quantity-input`).edit("4", { confirm: false });
await contains(`.o_add_qty`).click();
expect(queryAllTexts(`.o_badges_list .badge`)).toEqual(["1", "2", "3", "5", "10"]);
expect(`.o_notification`).toHaveCount(1);
expect(`.o_notification .o_notification_content`).toHaveText(
"At most 5 quantities can be displayed simultaneously. Remove a selected quantity to add others.",
{ message: "Can not add more then 5 quantities" }
);
expect(`.o_notification .o_notification_bar`).toHaveClass("bg-warning");
});

View file

@ -1,139 +0,0 @@
odoo.define('product.pricelist.report.tests', function (require) {
"use strict";
const GeneratePriceList = require('product.generate_pricelist').GeneratePriceList;
const testUtils = require('web.test_utils');
const { createWebClient, doAction } = require('@web/../tests/webclient/helpers');
const { getFixture, patchWithCleanup } = require("@web/../tests/helpers/utils");
let serverData;
QUnit.module('Product Pricelist', {
beforeEach: function () {
this.data = {
'product.product': {
fields: {
id: {type: 'integer'}
},
records: [{
id: 42,
display_name: "Customizable Desk"
}]
},
'product.pricelist': {
fields: {
id: {type: 'integer'}
},
records: [{
id: 1,
display_name: "Public Pricelist"
}, {
id: 2,
display_name: "Test"
}]
}
};
serverData = { models: this.data };
},
}, function () {
QUnit.test('Pricelist Client Action', async function (assert) {
assert.expect(23);
let Qty = [1, 5, 10]; // default quantities
patchWithCleanup(GeneratePriceList.prototype, {
_onFieldChanged: function (event) {
assert.step('field_changed');
return this._super.apply(this, arguments);
},
_onQtyChanged: function (event) {
assert.deepEqual(event.data.quantities, Qty.sort((a, b) => a - b), "changed quantity should be same.");
assert.step('qty_changed');
return this._super.apply(this, arguments);
},
});
const mockRPC = (route, args) => {
if (route === '/web/dataset/call_kw/report.product.report_pricelist/get_html') {
return Promise.resolve("");
}
};
const target = getFixture();
const webClient = await createWebClient({ serverData, mockRPC });
await doAction(webClient, {
id: 1,
name: 'Generate Pricelist',
tag: 'generate_pricelist',
type: 'ir.actions.client',
context: {
'default_pricelist': 1,
'active_ids': [42],
'active_id': 42,
'active_model': 'product.product'
}
});
// checking default pricelist
assert.strictEqual($(target).find('.o_field_many2one input').val(), "Public Pricelist",
"should have default pricelist");
// changing pricelist
await testUtils.fields.many2one.clickOpenDropdown("pricelist_id");
await testUtils.fields.many2one.clickItem("pricelist_id", "Test");
// check wherther pricelist value has been updated or not. along with that check default quantities should be there.
assert.strictEqual($(target).find('.o_field_many2one input').val(), "Test",
"After pricelist change, the pricelist_id field should be updated");
assert.strictEqual($(target).find('.o_badges > .badge').length, 3,
"There should be 3 default Quantities");
// existing quantity can not be added.
await testUtils.dom.click($(target).find('.o_add_qty'));
let notificationElement = document.body.querySelector('.o_notification_manager .o_notification');
assert.strictEqual(notificationElement.querySelector('.o_notification_content').textContent,
"Quantity already present (1).", "Existing Quantity can not be added");
assert.hasClass(notificationElement, "border-info");
// adding few more quantities to check.
$(target).find('.o_product_qty').val(2);
Qty.push(2);
await testUtils.dom.click($(target).find('.o_add_qty'));
$(target).find('.o_product_qty').val(3);
Qty.push(3);
await testUtils.dom.click($(target).find('.o_add_qty'));
// should not be added more then 5 quantities.
$(target).find('.o_product_qty').val(4);
await testUtils.dom.click($(target).find('.o_add_qty'));
notificationElement = document.body.querySelector('.o_notification_manager .o_notification:nth-child(2)');
assert.strictEqual(notificationElement.querySelector('.o_notification_content').textContent,
"At most 5 quantities can be displayed simultaneously. Remove a selected quantity to add others.",
"Can not add more then 5 quantities");
assert.hasClass(notificationElement, "border-warning");
// removing all the quantities should work
Qty.pop(10);
await testUtils.dom.click($(target).find('.o_badges .badge:contains("10") .o_remove_qty'));
Qty.pop(5);
await testUtils.dom.click($(target).find('.o_badges .badge:contains("5") .o_remove_qty'));
Qty.pop(3);
await testUtils.dom.click($(target).find('.o_badges .badge:contains("3") .o_remove_qty'));
Qty.pop(2);
await testUtils.dom.click($(target).find('.o_badges .badge:contains("2") .o_remove_qty'));
Qty.pop(1);
await testUtils.dom.click($(target).find('.o_badges .badge:contains("1") .o_remove_qty'));
assert.verifySteps([
'field_changed',
'qty_changed',
'qty_changed',
'qty_changed',
'qty_changed',
'qty_changed',
'qty_changed',
'qty_changed'
]);
});
}
);
});

View file

@ -0,0 +1,13 @@
import { defineModels } from '@web/../tests/web_test_helpers';
import { ProductProduct } from './mock_server/mock_models/product_product';
import { ProductTemplate } from './mock_server/mock_models/product_template';
export const productModels = {
ProductProduct,
ProductTemplate,
};
export function defineProductModels() {
defineModels(productModels);
}