| 1 |
import { mailDataHelpers } from "@mail/../tests/mock_server/mail_mock_server"; |
| 2 |
|
| 3 |
import { fields, makeKwArgs, models } from "@web/../tests/web_test_helpers"; |
| 4 |
|
| 5 |
export class WebsiteVisitor extends models.ServerModel { |
| 6 |
_name = "website.visitor"; |
| 7 |
|
| 8 |
country_id = fields.Many2one({ relation: "res.country", string: "Country" }); // FIXME: somehow not fetched properly |
| 9 |
display_name = fields.Char({ compute: "_compute_display_name" }); |
| 10 |
page_visit_history = fields.Char(); |
| 11 |
lang_id = fields.Many2one({ relation: "res.lang", string: "Language" }); // FIXME: somehow not fetched properly |
| 12 |
partner_id = fields.Many2one({ relation: "res.partner", string: "Contact" }); // FIXME: somehow not fetched properly |
| 13 |
website_id = fields.Many2one({ relation: "website", string: "Website" }); |
| 14 |
|
| 15 |
_compute_display_name() { |
| 16 |
for (const record of this) { |
| 17 |
record.display_name = |
| 18 |
this.env["res.partner"].browse(record.partner_id)[0]?.name || |
| 19 |
`Website Visitor #${record.id}`; |
| 20 |
} |
| 21 |
} |
| 22 |
|
| 23 |
/** @param {number[]} ids */ |
| 24 |
_to_store(store) { |
| 25 |
/** @type {import("mock_models").ResCountry} */ |
| 26 |
const ResCountry = this.env["res.country"]; |
| 27 |
/** @type {import("mock_models").ResLang} */ |
| 28 |
const ResLang = this.env["res.lang"]; |
| 29 |
/** @type {import("mock_models").ResPartner} */ |
| 30 |
const ResPartner = this.env["res.partner"]; |
| 31 |
/** @type {import("mock_models").Website} */ |
| 32 |
const Website = this.env["website"]; |
| 33 |
|
| 34 |
for (const visitor of this) { |
| 35 |
const [data] = this._read_format(visitor.id, ["display_name"]); |
| 36 |
data.country_id = mailDataHelpers.Store.one(ResCountry.browse(visitor.country_id)); |
| 37 |
data.page_visit_history = JSON.parse(visitor.page_visit_history || "[]"); |
| 38 |
data.lang_id = mailDataHelpers.Store.one(ResLang.browse(visitor.lang_id)); |
| 39 |
data.partner_id = mailDataHelpers.Store.one( |
| 40 |
ResPartner.browse(visitor.partner_id), |
| 41 |
makeKwArgs({ fields: ["country_id"] }) |
| 42 |
); |
| 43 |
data.website_id = mailDataHelpers.Store.one(Website.browse(visitor.website_id)); |
| 44 |
store._add_record_fields(this.browse(visitor.id), data); |
| 45 |
} |
| 46 |
} |
| 47 |
} |