[IMP] web: add DynamicModelFieldSelectorChar widget
In this commit we create a DynamicModelFieldSelectorChar widget. Purpose is to
use it in WhatsApp to select fields when trying to make a valid path to find
information on a given model. Example
<field name="xxx" widget="DynamicModelFieldSelectorChar"
options="{'only_searchable': true}"/>
It is based on char widget, using only_searchable options.
Task-2377154 (Add WhatsApp Support)
Part-of: odoo/odoo#134377
Co-authored-by: Akshat Trivedi <aktr@odoo.com>
Co-authored-by: Aurélien Warnon <awa@odoo.com>
Co-authored-by: Gitashri Mantha <gman@odoo.com>
Co-authored-by: Jigar Vaghela <jva@odoo.com>
Co-authored-by: Kashyap Patel <kasp@odoo.com>
Co-authored-by: Khushi Vakil <khva@odoo.com>
Co-authored-by: Nishant Jain <niai@odoo.com>
Co-authored-by: Prakash Prajapati <ppr@odoo.com>
Co-authored-by: Priyanshi patel <prpa@odoo.com>
Co-authored-by: Rahul Prajapati <rapr@odoo.com>
Co-authored-by: Renaud Thiry <reth@odoo.com>
Co-authored-by: Shreya Patel <shpa@odoo.com>
Co-authored-by: Stéphane Debauche <std@odoo.com>
Co-authored-by: Zeel Patel <zepa@odoo.com>
This commit is contained in:
committed by
Renaud Thiry
co-authored by
Akshat Trivedi
Aurélien Warnon
Gitashri Mantha
Jigar Vaghela
Kashyap Patel
Khushi Vakil
Prakash Prajapati
Priyanshi patel
Rahul Prajapati
Renaud Thiry
Shreya Patel
Stéphane Debauche
Zeel Patel
parent
9a7c187147
commit
fe62bfeacb
@@ -0,0 +1,12 @@
|
||||
/** @odoo-module */
|
||||
|
||||
import { ModelFieldSelector } from "@web/core/model_field_selector/model_field_selector";
|
||||
|
||||
export class DynamicModelFieldSelector extends ModelFieldSelector {
|
||||
|
||||
static props = {
|
||||
...ModelFieldSelector.props,
|
||||
record: { type: Object, optional: true },
|
||||
recordProps: { type: Object, optional: true },
|
||||
};
|
||||
}
|
||||
+74
@@ -0,0 +1,74 @@
|
||||
/** @odoo-module */
|
||||
|
||||
import { CharField, charField } from "@web/views/fields/char/char_field";
|
||||
import { registry } from "@web/core/registry";
|
||||
import { archParseBoolean } from "@web/views/utils";
|
||||
|
||||
import { DynamicModelFieldSelector } from "./dynamic_model_field_selector";
|
||||
|
||||
export class DynamicModelFieldSelectorChar extends CharField {
|
||||
static components = {
|
||||
...CharField.components,
|
||||
DynamicModelFieldSelector
|
||||
};
|
||||
|
||||
static props = {
|
||||
...CharField.props,
|
||||
resModel : { type: String, optional: true },
|
||||
onlySearchable: { type: Boolean, optional: true },
|
||||
followRelations: { type: Boolean, optional: true },
|
||||
}
|
||||
|
||||
/**
|
||||
* Update record
|
||||
*
|
||||
* @param {string} value
|
||||
* @private
|
||||
*/
|
||||
async _onRecordUpdate(value) {
|
||||
await this.props.record.update({[this.props.name]: value});
|
||||
}
|
||||
|
||||
//---- Getters ----
|
||||
get getSelectorProps() {
|
||||
return {
|
||||
path: this.props.record.data[this.props.name],
|
||||
resModel: this.getResModel(),
|
||||
readonly: this.props.readonly,
|
||||
record: this.props.record,
|
||||
recordProps: this.props,
|
||||
update: this._onRecordUpdate.bind(this),
|
||||
isDebugMode: !!this.env.debug,
|
||||
filter: this.filter.bind(this),
|
||||
followRelations: this.props.followRelations,
|
||||
};
|
||||
}
|
||||
|
||||
filter(fieldDef) {
|
||||
return !this.props.onlySearchable || fieldDef.searchable;
|
||||
}
|
||||
|
||||
getResModel(props = this.props) {
|
||||
const resModel = props.record.data[props.resModel];
|
||||
if (!resModel) {
|
||||
return props.record.resModel;
|
||||
}
|
||||
return resModel;
|
||||
}
|
||||
}
|
||||
|
||||
DynamicModelFieldSelectorChar.template = "web.DynamicModelFieldSelectorChar";
|
||||
|
||||
export const dynamicModelFieldSelectorChar = {
|
||||
...charField,
|
||||
component: DynamicModelFieldSelectorChar,
|
||||
extractProps({ options }, dynamicInfo) {
|
||||
return {
|
||||
followRelations: options.follow_relations ?? true,
|
||||
onlySearchable: archParseBoolean(options.only_searchable),
|
||||
resModel: options.model,
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
registry.category("fields").add("DynamicModelFieldSelectorChar", dynamicModelFieldSelectorChar);
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<templates xml:space="preserve">
|
||||
<t t-name="web.DynamicModelFieldSelectorChar" t-inherit="web.CharField" t-inherit-mode="primary" owl="1">
|
||||
<xpath expr="//input" position="attributes">
|
||||
<attribute name="class" add="d-none" separator=" "/>
|
||||
</xpath>
|
||||
<xpath expr="//span" position="attributes">
|
||||
<attribute name="class" add="d-none" separator=" "/>
|
||||
</xpath>
|
||||
<xpath expr="//t[@t-if='props.readonly']" position="before">
|
||||
<DynamicModelFieldSelector t-props="getSelectorProps" />
|
||||
</xpath>
|
||||
</t>
|
||||
</templates>
|
||||
@@ -184,6 +184,10 @@ addons/spreadsheet/static/src/o_spreadsheet/o_spreadsheet.js
|
||||
!addons/website_livechat/
|
||||
!addons/website_livechat/**/*
|
||||
|
||||
# Whitelist whatsapp
|
||||
!whatsapp
|
||||
!whatsapp/**/*
|
||||
|
||||
# Whitelist point_of_sale
|
||||
!addons/point_of_sale/
|
||||
!addons/point_of_sale/**/*
|
||||
@@ -243,6 +247,8 @@ addons/spreadsheet/static/src/o_spreadsheet/o_spreadsheet.js
|
||||
!pos_restaurant_iot/**/*
|
||||
!pos_settle_due
|
||||
!pos_settle_due/**/*
|
||||
!whatsapp_pos
|
||||
!whatsapp_pos/**/*
|
||||
|
||||
# Whitelist misc enterprise modules
|
||||
!sign
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
"@bus/*": ["addons/bus/static/src/*"],
|
||||
"@mail/*": ["addons/mail/static/src/*"],
|
||||
"@im_livechat/*": ["addons/im_livechat/static/src/*"],
|
||||
"@whatsapp/*": ["addons/whatsapp/static/src/*"],
|
||||
"@point_of_sale/*": ["addons/point_of_sale/static/src/*"],
|
||||
|
||||
"@l10n_co_pos/*": ["addons/l10n_co_pos/static/src/*"],
|
||||
@@ -42,7 +43,8 @@
|
||||
"@pos_sale_product_configurator/*": ["addons/pos_sale_product_configurator/static/src/*"],
|
||||
"@pos_six/*": ["addons/pos_six/static/src/*"],
|
||||
"@pos_stripe/*": ["addons/pos_stripe/static/src/*"],
|
||||
"@test_mail/*": ["addons/test_mail/static/src/*"]
|
||||
"@test_mail/*": ["addons/test_mail/static/src/*"],
|
||||
"@whatsapp_pos/*": ["addons/whatsapp_pos/static/src/*"]
|
||||
}
|
||||
},
|
||||
"include": ["**/*.js", "**/*.ts"],
|
||||
|
||||
Reference in New Issue
Block a user