| 1 |
import { MockServer, models } from "@web/../tests/web_test_helpers"; |
| 2 |
|
| 3 |
export class PosSession extends models.ServerModel { |
| 4 |
_name = "pos.session"; |
| 5 |
_orderRef = 1; |
| 6 |
|
| 7 |
_load_pos_data_models(config_id) { |
| 8 |
return [ |
| 9 |
"pos.session", |
| 10 |
"pos.config", |
| 11 |
"pos.preset", |
| 12 |
"resource.calendar.attendance", |
| 13 |
"pos.order", |
| 14 |
"pos.order.line", |
| 15 |
"pos.pack.operation.lot", |
| 16 |
"pos.payment", |
| 17 |
"pos.payment.method", |
| 18 |
"pos.printer", |
| 19 |
"pos.category", |
| 20 |
"pos.bill", |
| 21 |
"res.company", |
| 22 |
"account.tax", |
| 23 |
"account.tax.group", |
| 24 |
"product.template", |
| 25 |
"product.product", |
| 26 |
"product.attribute", |
| 27 |
"product.attribute.custom.value", |
| 28 |
"product.template.attribute.line", |
| 29 |
"product.template.attribute.value", |
| 30 |
"product.template.attribute.exclusion", |
| 31 |
"product.combo", |
| 32 |
"product.combo.item", |
| 33 |
"res.users", |
| 34 |
"res.partner", |
| 35 |
"product.uom", |
| 36 |
"decimal.precision", |
| 37 |
"uom.uom", |
| 38 |
"res.country", |
| 39 |
"res.country.state", |
| 40 |
"res.lang", |
| 41 |
"product.category", |
| 42 |
"product.pricelist", |
| 43 |
"product.pricelist.item", |
| 44 |
"account.cash.rounding", |
| 45 |
"account.fiscal.position", |
| 46 |
"stock.picking.type", |
| 47 |
"res.currency", |
| 48 |
"pos.note", |
| 49 |
"product.tag", |
| 50 |
"ir.module.module", |
| 51 |
]; |
| 52 |
} |
| 53 |
|
| 54 |
_load_pos_data_fields() { |
| 55 |
return [ |
| 56 |
"id", |
| 57 |
"name", |
| 58 |
"user_id", |
| 59 |
"config_id", |
| 60 |
"start_at", |
| 61 |
"stop_at", |
| 62 |
"payment_method_ids", |
| 63 |
"state", |
| 64 |
"update_stock_at_closing", |
| 65 |
"cash_register_balance_start", |
| 66 |
"access_token", |
| 67 |
]; |
| 68 |
} |
| 69 |
|
| 70 |
// These methods are designed to be overridden to customize the POS data loading behavior using the provided `opts`. |
| 71 |
getModelsToLoad(opts) { |
| 72 |
return this._load_pos_data_models(); |
| 73 |
} |
| 74 |
|
| 75 |
getModelFieldsToLoad(model, opts) { |
| 76 |
return model._load_pos_data_fields(); |
| 77 |
} |
| 78 |
|
| 79 |
processPosReadData(model, records, opts) { |
| 80 |
return (model._load_pos_data_read && model._load_pos_data_read(records)) || records; |
| 81 |
} |
| 82 |
|
| 83 |
load_data_params(opts = {}) { |
| 84 |
const modelToLoad = this.getModelsToLoad(opts); |
| 85 |
const response = modelToLoad.reduce((acc, modelName) => { |
| 86 |
acc[modelName] = { |
| 87 |
fields: {}, |
| 88 |
relations: {}, |
| 89 |
}; |
| 90 |
return acc; |
| 91 |
}, {}); |
| 92 |
|
| 93 |
for (const model of modelToLoad) { |
| 94 |
const serverModel = MockServer.env[model]; |
| 95 |
const posFields = this.getModelFieldsToLoad(serverModel, opts); |
| 96 |
const allFields = serverModel.fields_get(); |
| 97 |
const base = posFields.length ? posFields : Object.keys(allFields); |
| 98 |
|
| 99 |
if (!base.includes("id")) { |
| 100 |
base.push("id"); |
| 101 |
} |
| 102 |
|
| 103 |
for (const fieldName of base) { |
| 104 |
const field = allFields[fieldName]; |
| 105 |
|
| 106 |
if (!field) { |
| 107 |
console.debug(`Field ${fieldName} not found in model ${model}`); |
| 108 |
continue; |
| 109 |
} |
| 110 |
|
| 111 |
response[model]["relations"][fieldName] = { |
| 112 |
name: fieldName, |
| 113 |
model: model, |
| 114 |
compute: Boolean(field.compute), |
| 115 |
related: Boolean(field.related), |
| 116 |
type: field.type, |
| 117 |
relation: field.relation, |
| 118 |
inverse_name: field.inverse_fname_by_model_name?.[field.relation] || false, |
| 119 |
}; |
| 120 |
} |
| 121 |
|
| 122 |
response[model]["fields"] = posFields; |
| 123 |
} |
| 124 |
|
| 125 |
return response; |
| 126 |
} |
| 127 |
|
| 128 |
load_data(opts = {}) { |
| 129 |
const modelToLoad = this.getModelsToLoad(opts); |
| 130 |
const response = modelToLoad.reduce((acc, modelName) => { |
| 131 |
acc[modelName] = {}; |
| 132 |
return acc; |
| 133 |
}, {}); |
| 134 |
|
| 135 |
for (const modelName of modelToLoad) { |
| 136 |
const model = MockServer.env[modelName]; |
| 137 |
const posFields = this.getModelFieldsToLoad(model, opts); |
| 138 |
const records = model.search_read([], posFields, false, false, false, false); |
| 139 |
response[modelName] = this.processPosReadData(model, records, opts); |
| 140 |
} |
| 141 |
|
| 142 |
return response; |
| 143 |
} |
| 144 |
|
| 145 |
_load_pos_data_read(data) { |
| 146 |
data[0]["_partner_commercial_fields"] = []; |
| 147 |
data[0]["_server_version"] = "18.3+e"; |
| 148 |
data[0]["_base_url"] = "http://localhost:4444"; |
| 149 |
data[0]["_data_server_date"] = "2025-07-03 12:40:15"; |
| 150 |
data[0]["_has_cash_move_perm"] = true; |
| 151 |
data[0]["_has_available_products"] = true; |
| 152 |
data[0]["_pos_special_products_ids"] = []; |
| 153 |
return data; |
| 154 |
} |
| 155 |
|
| 156 |
filter_local_data() { |
| 157 |
return {}; |
| 158 |
} |
| 159 |
|
| 160 |
_records = [ |
| 161 |
{ |
| 162 |
id: 1, |
| 163 |
name: "/", |
| 164 |
user_id: 2, |
| 165 |
config_id: 1, |
| 166 |
start_at: false, |
| 167 |
stop_at: false, |
| 168 |
payment_method_ids: [2, 1], |
| 169 |
state: "opening_control", |
| 170 |
update_stock_at_closing: false, |
| 171 |
cash_register_balance_start: 0.0, |
| 172 |
access_token: "e09c4843-c913-463a-959d-b9e235881201", |
| 173 |
}, |
| 174 |
]; |
| 175 |
} |