/** Part of Beyond. Collina Systems proprietary module. */ import { Component } from "@odoo/owl"; import { registry } from "@web/core/registry"; import { imageUrl } from "@web/core/utils/urls"; import { standardFieldProps } from "@web/views/fields/standard_field_props"; import { _t } from "@web/core/l10n/translation"; /** * Photo, or initials on peach when there is none (Panel General design). * * WHY NOT avatar_128. res.partner inherits avatar.mixin, which already draws * an SVG when the record has no photo, so this looked like reinventing the * core. It is not, for two reasons that CSS cannot reach: * * · The mixin writes ONE letter (`name[0]`), and the design asks for two. * · Its background is an HSL colour hashed from name + create_date, and the * text is hardcoded white — inside a base64 SVG served as an . The * colour is baked into the image, so no stylesheet can turn it into the * panel's peach. * * The other way out would be overriding _avatar_generate_svg on res.partner, * which is tempting and shorter. It was not taken because avatar_128 is used * far beyond this screen — the POS among them — and repainting every partner * avatar in the system is a decision for whoever designs those screens, not a * side effect of the customer list. */ export class BeyondAvatarInitials extends Component { static template = "beyond_base.AvatarInitials"; static props = { ...standardFieldProps }; get valor() { return this.props.record.data[this.props.name]; } get nombre() { const datos = this.props.record.data; return (datos.name || datos.display_name || "").trim(); } /** * First letter of the first word plus first letter of the last one: * "Alejandro Mcdonald" → "AM". A single word gives a single letter rather * than two from the same word, which reads like a typo. */ get iniciales() { const palabras = this.nombre.split(/\s+/).filter(Boolean); if (!palabras.length) { return "?"; } const primera = palabras[0][0]; const ultima = palabras.length > 1 ? palabras[palabras.length - 1][0] : ""; return (primera + ultima).toUpperCase(); } get url() { return imageUrl(this.props.record.resModel, this.props.record.resId, this.props.name, { unique: this.props.record.data.write_date, }); } } export const beyondAvatarInitials = { component: BeyondAvatarInitials, displayName: _t("Foto o iniciales"), supportedTypes: ["binary"], // name feeds the initials; write_date busts the image cache after a new // photo. Declaring them makes the views load them without each view // having to remember. fieldDependencies: [ { name: "name", type: "char" }, { name: "write_date", type: "datetime" }, ], }; registry.category("fields").add("beyond_avatar_initials", beyondAvatarInitials);