Skip to Content
Odoo Menu
  • Prisijungti
  • Išbandykite nemokamai
  • Programėlės
    Finansai
    • Apskaita
    • Pateikimas apmokėjimui
    • Sąnaudos
    • Skaičiuoklė (BI)
    • Dokumentai
    • Pasirašymas
    Pardavimai
    • CRM
    • Pardavimai
    • Kasų sistema - Parduotuvė
    • Kasų sistema - Restoranas
    • Prenumeratos
    • Nuoma
    Svetainės
    • Svetainių kūrėjimo įrankis
    • El. Prekyba
    • Internetinis Tinklaraštis
    • Forumas
    • Tiesioginis pokalbis
    • eMokymasis
    Tiekimo grandinė
    • Atsarga
    • Gamyba
    • PLM
    • Įsigijimai
    • Priežiūra
    • Kokybė
    Žmogaus ištekliai
    • Darbuotojai
    • Įdarbinimas
    • Atostogos
    • Įvertinimai
    • Rekomendacijos
    • Transporto priemonės
    Rinkodara
    • Socialinė rinkodara
    • Rinkodara el. paštu
    • SMS rinkodara
    • Renginiai
    • Rinkodaros automatizavimas
    • Apklausos
    Paslaugos
    • Projektas
    • Darbo laiko žiniaraščiai
    • Priežiūros tarnyba
    • Pagalbos tarnyba
    • Planavimas
    • Rezervacijos
    Produktyvumas
    • Diskucija
    • Patvirtinimai
    • IoT
    • VoIP
    • Žinių biblioteka
    • WhatsApp
    Trečiųjų šalių programos Odoo Studija Odoo debesijos platforma
  • Pramonės šakos
    Mažmeninė prekyba
    • Knygynas
    • Drabužių parduotuvė
    • Baldų parduotuvė
    • Maisto prekių parduotuvė
    • Techninės įrangos parduotuvė
    • Žaislų parduotuvė
    Food & Hospitality
    • Barai ir pub'ai
    • Restoranas
    • Greitasis maistas
    • Guest House
    • Gėrimų platintojas
    • Hotel
    Nekilnojamasis turtas
    • Real Estate Agency
    • Architektūros įmonė
    • Konstrukcija
    • Estate Managament
    • Sodininkauti
    • Turto savininkų asociacija
    Konsultavimas
    • Accounting Firm
    • Odoo Partneris
    • Marketing Agency
    • Teisinė firma
    • Talentų paieška
    • Auditai & sertifikavimas
    Gamyba
    • Textile
    • Metal
    • Furnitures
    • Maistas
    • Brewery
    • Įmonių dovanos
    Sveikata & Fitnesas
    • Sporto klubas
    • Akinių parduotuvė
    • Fitneso Centras
    • Sveikatos praktikai
    • Vaistinė
    • Kirpėjas
    Trades
    • Handyman
    • IT įranga ir palaikymas
    • Saulės energijos sistemos
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Kiti
    • Nonprofit Organization
    • Aplinkos agentūra
    • Reklaminių stendų nuoma
    • Fotografavimas
    • Dviračių nuoma
    • Programinės įrangos perpardavėjas
    Browse all Industries
  • Bendrija
    Mokykitės
    • Mokomosios medžiagos
    • Dokumentacija
    • Sertifikatai
    • Mokymai
    • Internetinis Tinklaraštis
    • Tinklalaidės
    Skatinkite švietinimą
    • Švietimo programa
    • Scale Up! Verslo žaidimas
    • Aplankykite Odoo
    Gaukite programinę įrangą
    • Atsisiųsti
    • Palyginkite versijas
    • Leidimai
    Bendradarbiauti
    • Github
    • Forumas
    • Renginiai
    • Vertimai
    • Tapkite partneriu
    • Services for Partners
    • Registruokite jūsų apskaitos įmonę
    Gaukite paslaugas
    • Susiraskite partnerį
    • Susirask buhalterį
    • Susitikti su konsultantu
    • Diegimo paslaugos
    • Klientų rekomendavimas
    • Palaikymas
    • Atnaujinimai
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Gaukite demo
  • Kainodara
  • Pagalba

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

  • CRM
  • e-Commerce
  • Apskaita
  • Atsarga
  • PoS
  • Projektas
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Žymos (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Žymos (View all)
odoo accounting v14 pos v15
About this forum
Pagalba

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

Prenumeruoti

Get notified when there's activity on this post

This question has been flagged
jsOWLodoo16features
1 Atsakyti
5554 Rodiniai
Portretas
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
Portretas
Atmesti
Portretas
Cybrosys Techno Solutions Pvt.Ltd
Best Answer

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
Portretas
Atmesti
Enjoying the discussion? Don't just read, join in!

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

Registracija
Related Posts Replies Rodiniai Veikla
Call JS code from button in header in Odoo 16
OWL odoo16features
Portretas
Portretas
Portretas
2
liep. 24
5934
How to trigger my odoo model function when I click on specific notebook tab in form view in odoo16
js odoo16features
Portretas
Portretas
Portretas
2
geg. 24
2493
My xml dosen't update when updating the module (Owl)
OWL odoo16features
Portretas
0
saus. 24
2741
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
Portretas
Portretas
1
spal. 23
3121
Dialog Box Closed when I clicked to "Filters" or "Groub by" or "Favorites" Odoo 16 OWL
OWL odoo16features
Portretas
0
rugs. 23
2154
Bendrija
  • Mokomosios medžiagos
  • Dokumentacija
  • Forumas
Atvirasis kodas
  • Atsisiųsti
  • Github
  • Runbot
  • Vertimai
Paslaugos
  • Odoo.sh talpinimas
  • Palaikymas
  • Atnaujinti
  • Pritaikytas programavimo kūrimas
  • Švietimas
  • Susirask buhalterį
  • Susiraskite partnerį
  • Tapkite partneriu
Apie mus
  • Mūsų įmonė
  • Prekės ženklo turtas
  • Susisiekite su mumis
  • Darbo pasiūlymai
  • Renginiai
  • Tinklalaidės
  • Internetinis Tinklaraštis
  • Klientai
  • Teisinis • Privatumas
  • Saugumas
الْعَرَبيّة 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 yra atvirojo kodo verslo programų rinkinys, kuris apima visas įmonės poreikius: CRM, El. Prekybą, Apskaitą, Atsargų, Kasų sistemą, Projektų valdymą ir kt.

Unikali Odoo vertės pasiūla – būti tuo pačiu metu labai lengvai naudojama ir visiškai integruota sistema.

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