Přejít na obsah
Odoo Menu
  • Přihlásit se
  • Vyzkoušejte zdarma
  • Aplikace
    Finance
    • Účetnictví
    • Fakturace
    • Výdaje
    • Spreadsheet (BI)
    • Dokumenty
    • Podpisy
    Prodej
    • CRM
    • Prodej
    • POS Obchod
    • POS Restaurace
    • Předplatné
    • Pronájem
    Webové stránky
    • Webové stránky
    • E-shop
    • Blog
    • Fórum
    • Živý chat
    • eLearning
    Dodavatelský řetězec
    • Sklad
    • Výroba
    • PLM
    • Nákup
    • Údržba
    • Kvalita
    Lidské zdroje
    • Zaměstnanci
    • Nábor
    • Volno
    • Hodnocení zaměstnanců
    • Doporučení
    • Vozový park
    Marketing
    • Marketing sociálních sítí
    • Emailový marketing
    • SMS Marketing
    • Události
    • Marketingová automatizace
    • Dotazníky
    Služby
    • Projekt
    • Časové výkazy
    • Práce v terénu
    • Helpdesk
    • Plánování
    • Schůzky
    Produktivita
    • Diskuze
    • Schvalování
    • IoT
    • VoIP
    • Znalosti
    • WhatsApp
    Aplikace třetích stran Odoo Studio Odoo cloudová platforma
  • Branže
    Maloobchod
    • Knihkupectví
    • Obchod s oblečením
    • Obchod s nábytkem
    • Potraviny
    • Obchod s hardwarem
    • Hračkářství
    Jídlo a pohostinství
    • Bar a Pub
    • Restaurace
    • Fast Food
    • Penzion
    • Distributor nápojů
    • Hotel
    Nemovitost
    • Realitní kancelář
    • Architektonická firma
    • Stavba
    • Správa nemovitostí
    • Zahradnictví
    • Asociace vlastníků nemovitosti
    Poradenství
    • Účetní firma
    • Odoo Partner
    • Marketingová agentura
    • Právník
    • Akvizice talentů
    • Audit a certifikace
    Výroba
    • Textile
    • Kov
    • Nábytek
    • Jídlo
    • Brewery
    • Korporátní dárky
    Zdraví a fitness
    • Sportovní klub
    • Prodejna brýli
    • Fitness Centrum
    • Wellness praktikové
    • Lékárna
    • Kadeřnictví
    Transakce
    • Údržbář
    • IT hardware a podpora
    • Systémy solární energie
    • Výrobce obuvi
    • Úklidové služby
    • Služby HVAC
    Ostatní
    • Nezisková organizace
    • Agentura pro životní prostředí
    • Pronájem billboardů
    • Fotografování
    • Leasing jízdních kol
    • Prodejce softwaru
    Browse all Industries
  • Komunita
    Edukační program
    • Tutoriály
    • Dokumentace
    • Certifikace
    • Vzdělávání
    • Blog
    • Podcast
    Podpora vzdělávání
    • Vzdělávací program
    • Scale Up! Hra na firmu
    • Navštivte Odoo
    Získat software
    • Stáhnout
    • Porovnejte edice
    • Verze
    Spolupráce
    • Github
    • Fórum
    • Události
    • Překlady
    • Stát se partnerem
    • Services for Partners
    • Registrujte svou účetní firmu
    Získat služby
    • Najít partnera
    • Najít účetní
    • Setkejte se s poradcem
    • Implementační služby
    • Zákaznické reference
    • Podpora
    • Upgrady
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Dohodnout demo
  • Ceník
  • Pomoc

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Účetnictví
  • Sklad
  • PoS
  • Projekty
  • MRP
All apps
You need to be registered to interact with the community.
All Posts Lidé Odznaky
Štítky (View all)
odoo accounting v14 pos v15
O tomto fóru
You need to be registered to interact with the community.
All Posts Lidé Odznaky
Štítky (View all)
odoo accounting v14 pos v15
O tomto fóru
Pomoc

How do I override functions outside the class in the Odoo 16 Owl framework?

Odebírat

Get notified when there's activity on this post

This question has been flagged
jsOWLodoo16features
1 Odpovědět
5541 Zobrazení
Avatar
Mahdi Berranem

How can I override a function outside a class in an OWL framework?

I want to override the parseField function!

 

odoo/addons/web/static/src/search/filter_menu/custom_filter_item.js:

/** @odoo-module **/

import { DatePicker, DateTimePicker } from "@web/core/datepicker/datepicker" ;
import { Domain } from "@web/core/domain" ;
import { Dropdown } from "@web/core/dropdown/dropdown" ;
import { serializeDate, serializeDateTime } from "@web/core/l10n/dates" ;
import { _lt } from "@web/core/l10n/translation" ;
import { registry } from "@web/core/registry" ;

import { Component, useState } from "@odoo/owl" ;

const { DateTime } = luxon;

const formatters = registry.
const parsers = registry.category( "parsers" );

const FIELD_TYPES = {
binary: "binary" ,
boolean: "boolean" ,
char: "char" ,
date: "date" ,
datetime: "datetime" ,
float: "number" ,
id: "id" ,
integer: "number " ,
json: "json" ,
html: "char" ,
many2many: "char" ,
many2one:
"number" ,
one2many: "char" ,
text: "char" ,
selection: "selection" ,
};

// FilterMenu parameters
const FIELD_OPERATORS = {
binary: [
{ symbol: "!=" , description: _lt( "is set" ), value: false },
{ symbol: "=" , description: _lt( "is not set" ), value: false },
],
boolean: [
{ symbol: "=" , description:
{ symbol: "!=" , description: _lt( "is No" ), value: true },
],
char: [
{ symbol: "ilike" , description: _lt( "contains" ) },
{ symbol: "not ilike" , description: _lt( "doesn't contain" ) },
{ symbol: "=" , description: _lt( "is equal to" ) },
{ symbol: "!=" , description: _lt( "is not equal to" ) },
{ symbol: "!=" , description:_lt( "is set" ), value: false},
{ symbol: "=" , description: _lt( "is not set" ), value: false },
],
json: [
{ symbol: "ilike" , description: _lt( "contains" ) },
{ symbol: "not ilike" , description: _lt( "doesn't contain" ) },
{ symbol: "=" , description: _lt( "is equal to" ) },
{ symbol: "!=" , description: _lt( " is not equal to" ) },
{ symbol: "!=" ,description: _lt( "is set" ), value:false },
{ symbol: "=" , description: _lt( "is not set" ), value: false },
],
date: [
{ symbol: "=" , description: _lt( "is equal to" ) },
{ symbol: "!=" , description: _lt( "is not equal to" ) },
{ symbol: ">" , description: _lt( "is after" ) },
{ symbol: " , description: _lt( "is before" ) ​​},
{ symbol: ">=" ,description: _lt( "is after or equal to" ) },
{ symbol: "<=" , description: _lt( "is before or equal to" ) },
{ symbol: "between" , description: _lt( "is between" ) },
{ symbol: "!=" , description: _lt( "is set" ), value: false },
{ symbol: "=" , description: _lt( "is not set" ), value: false },
],
datetime: [
{ symbol: "between" , description: _lt( "is between" ) },
{ symbol:"=" , description: _lt( "is equal to") },
{ symbol: "!=" , description: _lt( "is not equal to" ) },
{ symbol: ">" , description: _lt( "is after" ) },
{ symbol: " , description : _lt( "is before" ) ​​},
{ symbol: ">=" , description: _lt( "is after or equal to" ) },
{ symbol: "<=" , description: _lt( "is before or equal to" " ) },
{ symbol: "!=" , description: _lt( "is set" ), value:false },
{ symbol: "=", description: _lt( "is not set" ), value: false },
],
id: [{ symbol: "=" , description: _lt( "is" ) }],
number: [
{ symbol: "=" , description: _lt( "is equal to" ) },
{ symbol: "!=" , description: _lt( "is not equal to" ) },
{ symbol: ">" , description: _lt( "greater than" ) } ,
{ symbol: " , description: _lt( "less than" ) },
{ symbol: ">=" , description: _lt("greater than or equal to" ) },
{ symbol: "<=" , description: _lt( "less than or equal to" ) },
{ symbol: "!=" , description: _lt( "is set" ), value: false },
{ symbol: "=" , description: _lt( "is not set" ), value: false },
],
selection: [
{ symbol: "=" , description: _lt( "is" ) },
{ symbol: "!=" , description: _lt( "is not" ) },
{ symbol: "!=", description: _lt( "is set" ), value: false },
{ symbol: "=" , description: _lt( "is not set" ), value: false },
],
};

function parseField(field, value) {
if (FIELD_TYPES[field.type] === "char" ) {
return value;
}
const type = field.type === "id" ? "integer" : field.type;
const parse = parsers.contains(type) ? parsers.get(type) : (v) => v;
return parse(value);
}

function formatField(field,
if (FIELD_TYPES[field.type] === "char" ) {
return value;
}
const type = field.type === "id" ? "integer" : field.type;
const format = formatters.contains(type) ? formatters.get(type) : (v) => v;
return format(value, { digits: field.digits });
}

export class CustomFilterItem extends Component {
setup() {
this .conditions = useState([]);
// Format, filter and sort the fields props
this .fields = Object.values( this .env.searchModel.searchViewFields)
.filter((field) => this.validateField(field))
.concat({ string: "ID" , type: "id" , name: "id" })
.sort(({ string: a }, { string: b }) => (a > b ? 1 : a < b ? - 1 : 0 ));

// Give access to constants variables to the template.
this .OPERATORS = FIELD_OPERATORS;
this .FIELD_TYPES = FIELD_TYPES;

// Add first condition
this .addNewCondition();
}

//------------------------------------------------------------- ----------------------
// Protected
//----------------------- -------------------------------------------

/**
* Populate the conditions list with a new condition having as properties:
* - the last condition or the first available field
* - the last condition or the first available operator
* - a null or empty array value
*/
addNewCondition() {
const lastCondition = [... this .conditions].pop();
const condition = lastCondition
? Object.assign({}, lastCondition)
: {
field: 0 ,
operator: 0 ,
};
this .setDefaultValue(condition);
Este.conditions.push(condition);
}

/**
* @param {Object} field
* @returns {boolean}
*/
validateField(field) {
return (
!field.deprecated && field.searchable && FIELD_TYPES[field.type] && field.name !== "id "
);
}

/**
* @param {Object} condition
*/
setDefaultValue(condition) {
const field = this .fields[condition.field];
const genericType = FIELD_TYPES[field.type];
const operator = FIELD_OPERATORS[genericType][condition.operator];
// Logical value
switch (genericType) {
case"id" :
case "number" : {
condition.value = 0 ;
break ;
}
case "date" :
case "datetime" : {
condition.value = [DateTime.local()];
if (operator.symbol === "between" ) {
condition.value.push(DateTime.local());
}
if (genericType === "datetime" ) {
condition.value[ 0 ] = condition.value[ 0 ].set({ hour: 0 , minute:, second: 0 });
if (operator.symbol === "between" ) {
condition.value[ 1 ] = condition.value[ 1 ].set({
hour: 23 ,
minute: 59 ,
second: 59 ,
});
}
}
break ;
}
case "selection" : {
const [firstValue] = this .fields[condition.field].selection[ 0];
condition.value = firstValue;
break ;
}
default : {
condition.value = "" ;
}
}
// Displayed value (not needed for dates: they are handled by the DatePicker component)
if (![ "date" , "datetime" ].includes(field.type)) {
condition.displayedValue = formatField(field, condition .value);
}
}

//---------------------------------------------------------- -----------------------
// Handlers
//---------------------- --------------------------------------------

/**
* Convert all conditions to prefilters.
*/
onApply() {
const preFilters = this .conditions.map((condition) => {
const field = this .fields[condition.field];
const genericType = this .FIELD_TYPES[field.type];
const operator = this . OPERATORS[genericType][condition.operator];
const descriptionArray = [field.string, operator.description.toString()];
const domainArray = [];
let domainValue;
// Field type specifics
if ( "value" in operator) {
domainValue = [operator.value];
// No description to push here
} else if ([ "date" , "datetime" ].includes(genericType)) {
const serialize = genericType === "date" ? serializeDate : serializeDateTime;
domainValue = condition.value.map(serialize);
descriptionArray.push(
` "${condition.value
.map((val) => formatField(field, val))
.join( " " + this .env.

else {
domainValue = [condition.value];
if (field.type === "selection" ) {
descriptionArray.push(
` "${field.selection.find((v) => v[0] === condition.value)[1]}" `
) ;
} else {
descriptionArray.push(` "${condition.value}" `);
}
}
// Operator specifics
if (operator.symbol === "between" ) {
domainArray.push(
[field.name,, domainValue[ 0 ]],
[field.name, "<=" , domainValue[ 1 ]]
);
} else {
domainArray.push([field.name, operator.symbol, domainValue[ 0 ]]);
}
const preFilter = {
description: descriptionArray.join( " " ),
domain: new Domain(domainArray).toString(),
type: "filter" ,
};
return preFilter;
});

Este.env.searchModel.createNewFilters(preFilters);

// remove conditions
while ( this .conditions.length) {
this .conditions.pop();
}

this .addNewCondition();
}

/**
* @param {Object} condition
* @param {number} valueIndex
* @param {Date} ev
*/
onDateTimeChanged(condition, valueIndex, date) {
condition.value[valueIndex] = date;
}

/**
* @param {Object} condition
* @param {Event} ev
*/
onFieldSelect(condition, ev) {
Object.assign(condition, {
field: ev.target.selectedIndex,
operator: 0 ,
});
this .setDefaultValue(condition);
}

/**
* @param {Object} condition
* @param {Event} ev
*/
onOperatorSelect(condition, ev) {
condition.operator = ev.target.selectedIndex;
this .setDefaultValue(condition);
}

/**
* @param {Object} condition
*/
onRemoveCondition(conditionIndex) {
this .conditions.splice(conditionIndex, 1 );
}

/**
* @param {Object} condition
* @param {Event} ev
*/
onValueChange(condition, ev) {
if (!ev.target.value) {
return this .setDefaultValue(condition);
}
const field = this .fields[condition.field];
try {
const parsed = parseField(field, ev.target.value);
const formatted = formatField(field, parsed);
// Only updates values ​​if it can be correctly parsed and formatted.
condition.value = parsed;
condition.displayedValue = formatted;
} catch (_err) {
// Parsing error: nothing is done
}
// Only reset the target's value if it is not a selection field.
if (field.type !== "selection" ) {
ev.target.value = condition.displayedValue;
}
}
}

CustomFilterItem.components = { DatePicker, DateTimePicker, Dropdown };
CustomFilterItem.template = "web.CustomFilterItem" ;



0
Avatar
Zrušit
Avatar
Cybrosys Techno Solutions Pvt.Ltd
Nejlepší odpověď

Hi,

You can't override the parseField function because it is not part of a class;

it is just a standalone function. Overriding is a method in object-oriented

programming where a function in the child class has the same name as a

function in the parent class, so the child class function overrides the parent class function.


Instead of trying to override, you can rewrite the function based on your needs:


function parseField(field, value) {

    // write your logic here

}


//And then patch the class where the function used


//import the CustomFilterItem in the path

import CustomFilterItem from 'web.CustomFilterItem';

//import patch

import { patch } from 'web.utils';


patch(CustomFilterItem.prototype, 'patch.CustomFilterItem', {

    // override the  onValueChange because the parseField function is used inside the onValueChange function

    // if the name of parseField is changed, you should change the name of the parseField in the onValueChange

    // like  const parsed = newParseField(field, ev.target.value);


    onValueChange(condition, ev) {

        if (!ev.target.value) {

            return this.setDefaultValue(condition);

        }

        const field = this.fields[condition.field];

        try {

            const parsed = parseField(field, ev.target.value);

            const formatted = formatField(field, parsed);

            // Only updates values if it can be correctly parsed and formatted.

            condition.value = parsed;

            condition.displayedValue = formatted;

        } catch (_err) {

            // Parsing error: nothing is done

        }

        // Only reset the target's value if it is not a selection field.

        if (field.type !== "selection") {

            ev.target.value = condition.displayedValue;

        }

    }

});



Hope this helps.

0
Avatar
Zrušit
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Přihlásit se
Related Posts Odpovědi Zobrazení Aktivita
Call JS code from button in header in Odoo 16
OWL odoo16features
Avatar
Avatar
Avatar
2
čvc 24
5926
How to trigger my odoo model function when I click on specific notebook tab in form view in odoo16
js odoo16features
Avatar
Avatar
Avatar
2
kvě 24
2490
My xml dosen't update when updating the module (Owl)
OWL odoo16features
Avatar
0
led 24
2737
in odoo16 owl, how to store current page state after go to another page, and restore them when back to this page from the breadcrumbs?
OWL odoo16features
Avatar
Avatar
1
říj 23
3116
Dialog Box Closed when I clicked to "Filters" or "Groub by" or "Favorites" Odoo 16 OWL
OWL odoo16features
Avatar
0
zář 23
2145
Komunita
  • Tutoriály
  • Dokumentace
  • Fórum
Open Source
  • Stáhnout
  • Github
  • Runbot
  • Překlady
Služby
  • Odoo.sh hostování
  • Podpora
  • Upgrade
  • Nestandardní vývoj
  • Edukační program
  • Najít účetní
  • Najít partnera
  • Stát se partnerem
O nás
  • Naše společnost
  • Podklady značky
  • Kontakujte nás
  • Práce
  • Události
  • Podcast
  • Blog
  • Zákazníci
  • Právní dokumenty • Soukromí
  • Zabezpečení
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo je balíček open-source aplikací, které pokrývají všechny potřeby vaší společnosti: CRM, e-shop, účetnictví, sklady, kasy, projektové řízení a další.

Unikátní nabídka od Odoo poskytuje velmi jednoduché uživatelské rozhraní a vše je integrované na jednom místě.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now