mirror of
https://github.com/bringout/oca-ocb-pos.git
synced 2026-04-24 04:22:07 +02:00
19.0 vanilla
This commit is contained in:
parent
6e54c1af6c
commit
3ca647e428
1087 changed files with 132065 additions and 108499 deletions
|
|
@ -0,0 +1,25 @@
|
|||
import { test, expect } from "@odoo/hoot";
|
||||
import { setupPosEnv } from "@point_of_sale/../tests/unit/utils";
|
||||
import { CashierName } from "@point_of_sale/app/components/navbar/cashier_name/cashier_name";
|
||||
import { mountWithCleanup } from "@web/../tests/web_test_helpers";
|
||||
import { definePosModels } from "@point_of_sale/../tests/unit/data/generate_model_definitions";
|
||||
|
||||
definePosModels();
|
||||
|
||||
test("avatarAndCssClass", async () => {
|
||||
await setupPosEnv();
|
||||
const comp = await mountWithCleanup(CashierName, {});
|
||||
expect(comp.avatar).toBe("/web/image/hr.employee.public/2/avatar_128");
|
||||
expect(comp.cssClass).toMatchObject({ oe_status: true });
|
||||
});
|
||||
test("selectCashier", async () => {
|
||||
const store = await setupPosEnv();
|
||||
const comp = await mountWithCleanup(CashierName, {});
|
||||
const result = await comp.selectCashier();
|
||||
expect(result.name).toBe("Employee1");
|
||||
expect(result.id).toBe(3);
|
||||
store.setCashier(result);
|
||||
const value = store.getCashier();
|
||||
expect(value.name).toBe("Employee1");
|
||||
expect(value.id).toBe(3);
|
||||
});
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
import { test, expect } from "@odoo/hoot";
|
||||
import { setupPosEnv } from "@point_of_sale/../tests/unit/utils";
|
||||
import { Navbar } from "@point_of_sale/app/components/navbar/navbar";
|
||||
import { mountWithCleanup } from "@web/../tests/web_test_helpers";
|
||||
import { definePosModels } from "@point_of_sale/../tests/unit/data/generate_model_definitions";
|
||||
|
||||
definePosModels();
|
||||
|
||||
test("showCreateProductButtonWithAdmin", async () => {
|
||||
const store = await setupPosEnv();
|
||||
const admin = store.models["hr.employee"].get(2);
|
||||
store.setCashier(admin);
|
||||
const comp = await mountWithCleanup(Navbar, {});
|
||||
expect(comp.showCreateProductButton).toBe(true);
|
||||
});
|
||||
|
||||
test("showCreateProductButtonWithNonAdmin", async () => {
|
||||
const store = await setupPosEnv();
|
||||
const emp = store.models["hr.employee"].get(3);
|
||||
store.setCashier(emp);
|
||||
const comp = await mountWithCleanup(Navbar, {});
|
||||
expect(comp.showCreateProductButton).toBe(false);
|
||||
});
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
import { test, expect } from "@odoo/hoot";
|
||||
import { setupPosEnv } from "@point_of_sale/../tests/unit/utils";
|
||||
import { CashMovePopup } from "@point_of_sale/app/components/popups/cash_move_popup/cash_move_popup";
|
||||
import { mountWithCleanup } from "@web/../tests/web_test_helpers";
|
||||
import { definePosModels } from "@point_of_sale/../tests/unit/data/generate_model_definitions";
|
||||
|
||||
definePosModels();
|
||||
|
||||
test("_prepareTryCashInOutPayload", async () => {
|
||||
await setupPosEnv();
|
||||
const comp = await mountWithCleanup(CashMovePopup, {
|
||||
props: { close: () => {} },
|
||||
});
|
||||
const result = comp._prepareTryCashInOutPayload();
|
||||
const employee_id = result[result.length - 1].employee_id;
|
||||
expect(employee_id).toBe(2);
|
||||
});
|
||||
test("partnerId", async () => {
|
||||
const store = await setupPosEnv();
|
||||
const comp = await mountWithCleanup(CashMovePopup, {
|
||||
props: { close: () => {} },
|
||||
});
|
||||
const emp = store.models["hr.employee"].get(2);
|
||||
store.setCashier(emp);
|
||||
expect(comp.partnerId).toBe(emp.work_contact_id.id);
|
||||
});
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
import { test, expect } from "@odoo/hoot";
|
||||
import { setupPosEnv } from "@point_of_sale/../tests/unit/utils";
|
||||
import { ProductInfoPopup } from "@point_of_sale/app/components/popups/product_info_popup/product_info_popup";
|
||||
import { mountWithCleanup } from "@web/../tests/web_test_helpers";
|
||||
import { definePosModels } from "@point_of_sale/../tests/unit/data/generate_model_definitions";
|
||||
|
||||
definePosModels();
|
||||
|
||||
test("allowProductEdition", async () => {
|
||||
const store = await setupPosEnv();
|
||||
store.addNewOrder();
|
||||
const admin = store.models["hr.employee"].get(2);
|
||||
store.setCashier(admin);
|
||||
const product = store.models["product.template"].get(5);
|
||||
const info = await store.getProductInfo(product, 1);
|
||||
const comp = await mountWithCleanup(ProductInfoPopup, {
|
||||
props: {
|
||||
productTemplate: product,
|
||||
info,
|
||||
close: () => {},
|
||||
},
|
||||
});
|
||||
expect(comp.allowProductEdition).toBe(true);
|
||||
const emp = store.models["hr.employee"].get(3);
|
||||
store.setCashier(emp);
|
||||
expect(comp.allowProductEdition).toBe(false);
|
||||
});
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
import { test, expect, describe } from "@odoo/hoot";
|
||||
import { setupPosEnv } from "@point_of_sale/../tests/unit/utils";
|
||||
import { LoginScreen } from "@point_of_sale/app/screens/login_screen/login_screen";
|
||||
import { mountWithCleanup } from "@web/../tests/web_test_helpers";
|
||||
import { definePosModels } from "@point_of_sale/../tests/unit/data/generate_model_definitions";
|
||||
|
||||
definePosModels();
|
||||
|
||||
describe("pos_login_screen.js", () => {
|
||||
test("openRegister", async () => {
|
||||
const store = await setupPosEnv();
|
||||
const comp = await mountWithCleanup(LoginScreen, {});
|
||||
comp.openRegister();
|
||||
expect(store.login).toBe(true);
|
||||
});
|
||||
test("backBtnName", async () => {
|
||||
const store = await setupPosEnv();
|
||||
store.login = true;
|
||||
const comp = await mountWithCleanup(LoginScreen, {});
|
||||
expect(comp.backBtnName).toBe("Discard");
|
||||
});
|
||||
});
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
import { test, expect } from "@odoo/hoot";
|
||||
import { setupPosEnv } from "@point_of_sale/../tests/unit/utils";
|
||||
import { PaymentScreen } from "@point_of_sale/app/screens/payment_screen/payment_screen";
|
||||
import { mountWithCleanup } from "@web/../tests/web_test_helpers";
|
||||
import { definePosModels } from "@point_of_sale/../tests/unit/data/generate_model_definitions";
|
||||
|
||||
definePosModels();
|
||||
|
||||
test("validateOrder", async () => {
|
||||
const store = await setupPosEnv();
|
||||
store.addNewOrder();
|
||||
const orderUuid = store.getOrder().uuid;
|
||||
const comp = await mountWithCleanup(PaymentScreen, {
|
||||
props: { orderUuid },
|
||||
});
|
||||
await comp.validateOrder();
|
||||
const order = store.getOrder();
|
||||
expect(order.employee_id.id).toBe(2);
|
||||
});
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
import { patch } from "@web/core/utils/patch";
|
||||
import { hootPosModels } from "@point_of_sale/../tests/unit/data/generate_model_definitions";
|
||||
import { models } from "@web/../tests/web_test_helpers";
|
||||
|
||||
export class HrEmployee extends models.ServerModel {
|
||||
_name = "hr.employee";
|
||||
|
||||
_load_pos_data_fields() {
|
||||
return ["name", "user_id", "work_contact_id"];
|
||||
}
|
||||
|
||||
_records = [
|
||||
{
|
||||
id: 2,
|
||||
name: "Administrator",
|
||||
user_id: 2,
|
||||
work_contact_id: 3,
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
name: "Employee1",
|
||||
user_id: 3,
|
||||
work_contact_id: 3,
|
||||
},
|
||||
];
|
||||
|
||||
_load_pos_data_read(records) {
|
||||
records.forEach((emp) => {
|
||||
if (emp.id === 2) {
|
||||
emp._role = "manager";
|
||||
} else {
|
||||
emp._role = "cashier";
|
||||
}
|
||||
});
|
||||
return records;
|
||||
}
|
||||
}
|
||||
patch(hootPosModels, [...hootPosModels, HrEmployee]);
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
import { PosConfig } from "@point_of_sale/../tests/unit/data/pos_config.data";
|
||||
|
||||
PosConfig._records = PosConfig._records.map((record) => ({
|
||||
...record,
|
||||
module_pos_hr: true,
|
||||
}));
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
import { patch } from "@web/core/utils/patch";
|
||||
import { PosOrder } from "@point_of_sale/app/models/pos_order";
|
||||
|
||||
patch(PosOrder.prototype, {
|
||||
_load_pos_data_fields() {
|
||||
return [...super._load_pos_data_fields(), "employee_id"];
|
||||
},
|
||||
});
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
import { patch } from "@web/core/utils/patch";
|
||||
import { PosPayment } from "@point_of_sale/../tests/unit/data/pos_payment.data";
|
||||
|
||||
patch(PosPayment.prototype, {
|
||||
_load_pos_data_fields() {
|
||||
return [...super._load_pos_data_fields(), "employee_id"];
|
||||
},
|
||||
});
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
import { patch } from "@web/core/utils/patch";
|
||||
import { PosSession } from "@point_of_sale/../tests/unit/data/pos_session.data";
|
||||
|
||||
patch(PosSession.prototype, {
|
||||
_load_pos_data_models() {
|
||||
return [...super._load_pos_data_models(), "hr.employee"];
|
||||
},
|
||||
_load_pos_data_fields() {
|
||||
return [...super._load_pos_data_fields(), "employee_id"];
|
||||
},
|
||||
});
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
import { test, expect } from "@odoo/hoot";
|
||||
import { setupPosEnv } from "@point_of_sale/../tests/unit/utils";
|
||||
import { definePosModels } from "@point_of_sale/../tests/unit/data/generate_model_definitions";
|
||||
|
||||
definePosModels();
|
||||
|
||||
test("getCashierName", async () => {
|
||||
const store = await setupPosEnv();
|
||||
store.addNewOrder();
|
||||
const emp = store.models["hr.employee"].get(3);
|
||||
store.setCashier(emp);
|
||||
const posOrder = store.getOrder();
|
||||
expect(posOrder.getCashierName()).toBe("Employee1");
|
||||
});
|
||||
|
|
@ -0,0 +1,86 @@
|
|||
import { test, expect } from "@odoo/hoot";
|
||||
import { setupPosEnv } from "@point_of_sale/../tests/unit/utils";
|
||||
import { definePosModels } from "@point_of_sale/../tests/unit/data/generate_model_definitions";
|
||||
import { patchWithCleanup } from "@web/../tests/web_test_helpers";
|
||||
|
||||
definePosModels();
|
||||
|
||||
test("createNewOrder", async () => {
|
||||
const store = await setupPosEnv();
|
||||
store.addNewOrder();
|
||||
const order = store.getOrder();
|
||||
expect(order.employee_id.id).toBe(2);
|
||||
});
|
||||
test("employeeIsAdmin", async () => {
|
||||
const store = await setupPosEnv();
|
||||
const emp = store.models["hr.employee"].get(2);
|
||||
store.setCashier(emp);
|
||||
expect(store.employeeIsAdmin).toBe(true);
|
||||
});
|
||||
test("_getConnectedCashier", async () => {
|
||||
const store = await setupPosEnv();
|
||||
expect(store._getConnectedCashier().id).toBe(2);
|
||||
});
|
||||
test("shouldShowOpeningControl", async () => {
|
||||
const store = await setupPosEnv();
|
||||
const emp = store.models["hr.employee"].get(2);
|
||||
store.setCashier(emp);
|
||||
store.hasLoggedIn = true;
|
||||
expect(store.shouldShowOpeningControl()).toBe(true);
|
||||
});
|
||||
test("allowProductCreation", async () => {
|
||||
const store = await setupPosEnv();
|
||||
const admin = store.models["hr.employee"].get(2);
|
||||
store.setCashier(admin);
|
||||
expect(await store.allowProductCreation()).toBe(true);
|
||||
const emp = store.models["hr.employee"].get(3);
|
||||
store.setCashier(emp);
|
||||
expect(await store.allowProductCreation()).toBe(false);
|
||||
});
|
||||
test("addLineToCurrentOrder", async () => {
|
||||
const store = await setupPosEnv();
|
||||
store.addNewOrder();
|
||||
const admin = store.models["hr.employee"].get(2);
|
||||
store.setCashier(admin);
|
||||
const product_id = store.models["product.product"].get(5);
|
||||
const result = await store.addLineToCurrentOrder({
|
||||
product_id: product_id,
|
||||
product_tmpl_id: product_id.product_tmpl_id,
|
||||
});
|
||||
expect(result.order_id.employee_id.id).toBe(2);
|
||||
});
|
||||
test("canEditPayment", async () => {
|
||||
const store = await setupPosEnv();
|
||||
store.addNewOrder();
|
||||
const order = store.getOrder();
|
||||
const admin = store.models["hr.employee"].get(2);
|
||||
store.setCashier(admin);
|
||||
expect(store.canEditPayment(order)).toBe(true);
|
||||
const emp = store.models["hr.employee"].get(3);
|
||||
store.setCashier(emp);
|
||||
expect(store.canEditPayment(order)).toBe(false);
|
||||
});
|
||||
test("handleUrlParams prevents unauthorized access when POS is locked with pos_hr", async () => {
|
||||
const store = await setupPosEnv();
|
||||
store.config.module_pos_hr = true;
|
||||
odoo.from_backend = false;
|
||||
|
||||
store.resetCashier();
|
||||
expect(store.cashier).toBe(false);
|
||||
expect(store.config.module_pos_hr).toBe(true);
|
||||
store.router.state.current = "ProductScreen";
|
||||
store.router.state.params = {};
|
||||
|
||||
let navigateCalledWithLoginScreen = false;
|
||||
patchWithCleanup(store.router, {
|
||||
navigate(routeName, routeParams) {
|
||||
if (routeName === "LoginScreen") {
|
||||
navigateCalledWithLoginScreen = true;
|
||||
}
|
||||
return super.navigate(routeName, routeParams);
|
||||
},
|
||||
});
|
||||
|
||||
await store.handleUrlParams();
|
||||
expect(navigateCalledWithLoginScreen).toBe(true);
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue