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
    • Textil
    • Kov
    • Nábytek
    • Jídlo
    • Pivovar
    • Korporátní dárky
    Zdraví a fitness
    • Sportovní klub
    • Prodejna brýli
    • Fitness Centrum
    • Wellness praktikové
    • Lékárna
    • Kadeřnictví
    Transakce
    • Údržbář
    • Podpora IT & hardware
    • 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
    Procházet všechna odvětví
  • 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
    • Služby pro partnery
    • 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

field color depending on value...

Odebírat

Get notified when there's activity on this post

This question has been flagged
viewsformwidgetWidgets
9272 Zobrazení
Avatar
Fatih Piristine

I needed something like monetary field to show unit of value.  1kg 0.3IU etc. so far ok. this is done.

when I tried to add colors into foreground. I loose state and can't push color attributes in to field.

i only have style= but nothing else. code is below, any advice appreciated. thanks.

widgets.js

(function() {

var instance = openerp;
var _t = instance.web._t;


instance.web.form.FieldNutrient = instance.web.form.FieldFloat.extend({
template: "FieldNutrient",
widget_class: 'oe_form_field_float oe_form_field_nutrient',
init: function() {
this._super.apply(this, arguments);

_nutrient = {
'value': this.get_value(),
'unit': null,
'digits': [16, 2],
'position': 'after',
'range': 0.05,
'color_low': '#c02c2c',
'color_high': '#c02c2c',
'color_ok': '#078B01',
'color': 'color:#078B01'
};

if (this.options.unit) {
_nutrient.unit = this.options.unit;
}

if (this.options.position) {
_nutrient.position = this.options.position;
}

if (this.options.digits) {
if (this.options.digits.length === 1) {
this.digits = _nutrient.digits = [16, this.options.digits];
} else {
this.digits = _nutrient.digits = this.options.digits;
}
}

this.set({"nutrient": _nutrient});
this.on("change:nutrient", this, this.get_color);
this.get_color();
},
start: function() {
var tmp = this._super();
this.on("change:nutrient", this, this.reinitialize);
return tmp;
},
get_color: function() {
_nutrient = this.get('nutrient');

if (_nutrient.value < 0) {
this.color = _nutrient.color = ''.concat('color:', _nutrient.color_low);
} else {
this.color = _nutrient.color = ''.concat('color:', _nutrient.color_ok);
}

this.set({"nutrient": _nutrient});
},
,
render_value: function() {
var show_value = this.format_value(this.get('value'), '');
if (!this.get("effective_readonly")) {
this.$el.find('input').val(show_value);
} else {
if (this.password) {
show_value = new Array(show_value.length + 1).join('*');
}
var char_content = this.$(".oe_form_char_content").text(show_value);
if (this.color) {
var _nutrient = this.get('nutrient');
_nutrient.value = this.get('value');
this.set({'nutrient': _nutrient});
this.get_color();
char_content.parent().css('color', this.color);
}
}
},
parse_value: function(val, def) {
return instance.web.parse_value(val, {type: "float", digits: this.digits}, def);
},
format_value: function(val, def) {
return instance.web.format_value(val, {type: "float", digits: this.digits}, def);
}
});

instance.web.form.widgets = instance.web.form.widgets.extend({
'nutrient': 'instance.web.form.FieldNutrient'
});

})();


widgets.xml

<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">

<t t-name="FieldNutrient" t-extend="FieldChar">
<t t-jquery="t:first" t-operation="before">
<t t-if="widget.get('nutrient') and widget.get('nutrient').unit and widget.get('nutrient').position === 'before'">
<t t-esc="widget.get('nutrient').unit"/>
</t>
</t>
<t t-jquery="t:last" t-operation="after">
<t t-if="widget.get('nutrient') and widget.get('nutrient').position and widget.get('nutrient').position === 'after'">
<t t-esc="widget.get('nutrient').unit"/>
</t>
</t>
</t>

</templates>


form_view.xml where field is called. widget parameters coming from options, hard-coded.

definition of fields:

dry_matter: float

amount_ingr_dry: float, computed

diff_ingry_dry: float, computed

<tr>
<td><label for="dry_matter"/></td>
<td><field name="dry_matter" class="oe_text_right" readonly="1" widget='nutrient' options="{'unit': 'kg', 'digits': [16,2], 'position': 'after'}"/></td>
<td><field name="amount_ingr_dry" class="oe_text_right" widget='nutrient' options="{'unit': 'kg', 'digits': [16,2], 'position': 'after'}"/></td>
<td><field name="diff_ingr_dry" class="oe_text_right" widget='nutrient' options="{'unit': 'kg', 'digits': [16,2], 'position': 'after'}"/></td>
</tr>


any ideas?


edit: ok i got the colors and units as needed. but left unit optional for now. added new column next to it to make it more readable.     


next one. to refer need value in widget, compare it with diff to get the colors properly defined by range. green red orange blue etc etc.


1
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
Display model creation view of another model
views form
Avatar
Avatar
2
úno 23
2733
Split View Odoo
views widget
Avatar
Avatar
1
led 19
6392
Resolve "handle" widget issue.
widget Widgets
Avatar
0
dub 16
4605
Why is my custom form view not being read by Odoo?
views form
Avatar
Avatar
2
zář 15
6590
When inherit view original view also changed ?
views form
Avatar
Avatar
1
bře 15
4709
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