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
    • Umělá inteligence
    • 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íInauguration Odoo Lyon
  • 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
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 to calculate a fields.function

Odebírat

Get notified when there's activity on this post

This question has been flagged
3 Odpovědi
15038 Zobrazení
Avatar
jean44

hello

please ! I need your help I want to add a fields.function 'cost' in my object that returns the sum of two fields from an other object "vehicule". I tried with this code but it seems not working " ProgrammingError: can't adapt type 'dict' "

class location_location(osv.osv):

_name = 'location.location'
def get_total(self, cr, uid, ids, values, arg, context):
x={}
for record in self.browse(cr, uid, ids):
    x[record.id]= record.vehicule_id.tarif_id.prixjournalier + record.vehicule_id.tarif_id.prixhebdomadaire
    return x

_columns = {
    'name': fields.char('ID',size=32,required=True),
    'vehicule_id': fields.many2one('vehicule.vehicule','Véhicule',required=True),
'cost' : fields.function(get_total, method=True, string='Total',type='float'),
}

location_location()

class vehicule_vehicule(osv.osv):

_name = 'vehicule.vehicule'
_columns = {
    'name': fields.char('ID', size=32, required=True, help='L\'identifiant du véhicule '),
'modele_id': fields.many2one('vehicule.modele','Modéle'),
'tarif_id': fields.many2one('vehicule.tarif','Tarif de location'),
    }

vehicule_vehicule()

class vehicule_tarif(osv.osv):

_name = 'vehicule.tarif'
_columns = {
'name': fields.char('ID', size=32, required=True),
    'prixjournalier': fields.integer('Prix journalier'),
    'prixhebdomadaire': fields.integer('Prix hebdomadaire'),
}

vehicule_tarif()

the value calculated will appear in the tree as "cost" please what I can do ?

1
Avatar
Zrušit
Abhishek H Menon

where is your vehicule model table?

Avatar
Abhishek H Menon
Nejlepší odpověď
from osv import fields,osv
class vehicule_tarif(osv.osv):
    _name = 'vehicule.tarif'
    _columns = {
                'name': fields.char('ID', size=32, required=True),
                'prixjournalier': fields.integer('Prix journalier'),
                'prixhebdomadaire': fields.integer('Prix hebdomadaire'),
                }
vehicule_tarif()

class vehicule_vehicule(osv.osv):
    _name = 'vehicule.vehicule'
    _columns = {
        'name': fields.char('ID', size=32, required=True, help='L\'identifiant du véhicule '),
#    'modele_id': fields.many2one('vehicule.modele','Modéle'),
       'tarif_id': fields.many2one('vehicule.tarif','Tarif de location'),
        }
vehicule_vehicule()    

class location_location(osv.osv):
    _name = 'location.location'
    def get_total(self, cr, uid, ids, values, arg, context):
        x={}
        print "get_total"
        for record in self.browse(cr, uid, ids):
            x[record.id]= record.vehicule_id.tarif_id.prixjournalier + record.vehicule_id.tarif_id.prixhebdomadaire
        return x

    _columns = {
        'name': fields.char('Name',size=32,required=True),
        'vehicule_id': fields.many2one('vehicule.vehicule','Véhicule',required=True),
        'cost' : fields.function(get_total, method=True, string='Total',type='float'),
        }
location_location()  

# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

and xml code for the above models

<openerp>
    <data>

    <!-- Test model View -->
    <menuitem id="menu_demo_sample" name="Demo Menu"
             sequence="3"/>
    <menuitem id="menu_demo_sub1" name="Locations" parent= "menu_demo_sample" sequence="1"/>

    <!-- Name : tarif : Tree View -->

    <record id="view_tarif_tree" model="ir.ui.view">
            <field name="name">vehicule.tarif</field>
            <field name="model">vehicule.tarif</field>
            <field name="type">tree</field>
            <field name="arch" type="xml">
                <tree string="Tarif">
                    <field name="name"/>

                </tree>
            </field>        
        </record>




        <!-- Name : tarif : Form View -->

        <record id="view_tarif_form" model="ir.ui.view">
            <field name="name">vehicule.tarif</field>
            <field name="model">vehicule.tarif</field>
            <field name="arch" type="xml">
                <form string="Tarif" version="7.0">
                    <group>         
                        <field name="name"/>
                        <field name="prixjournalier"/>
                        <field name="prixhebdomadaire"/>
                    </group>
                </form>
            </field>        
        </record>

        <!-- Name : vehicule : Tree View -->

    <record id="view_vehicule_tree" model="ir.ui.view">
            <field name="name">vehicule.vehicule</field>
            <field name="model">vehicule.vehicule</field>
            <field name="type">tree</field>
            <field name="arch" type="xml">
                <tree string="Vehicule">
                    <field name="name"/>


                </tree>
            </field>        
        </record>




        <!-- Name : vehicule : Form View -->

        <record id="view_vehicule_form" model="ir.ui.view">
            <field name="name">vehicule.vehicule</field>
            <field name="model">vehicule.vehicule</field>
            <field name="arch" type="xml">
                <form string="Vehicule" version="7.0">
                    <group>         
                        <field name="name"/>
                        <field name="tarif_id"/>
                    </group>
                </form>
            </field>        
        </record>

    <!-- Name : test : Tree View -->

        <record id="view_demo_tree" model="ir.ui.view">
            <field name="name">location.location</field>
            <field name="model">location.location</field>
            <field name="type">tree</field>
            <field name="arch" type="xml">
                <tree string="Location">
                    <field name="name"/>

                </tree>
            </field>        
        </record>




        <!-- Name : test : Form View -->

        <record id="view_demo_form" model="ir.ui.view">
            <field name="name">location.location</field>
            <field name="model">location.location</field>
            <field name="type">form</field>

            <field name="arch" type="xml">
                <form string="Location" version="7.0">
                    <group>             
                        <field name="name"/>
                        <field name="vehicule_id"/>
                        <field name="cost"/>
                    </group>    
                </form>
            </field>        
        </record>

        <!--Name : test Action : Action Menu  -->

        <record id="action_demo_menu" model="ir.actions.act_window">
            <field name="name">Demo Menu</field>
            <field name="type">ir.actions.act_window</field>
            <field name="res_model">location.location</field>
            <field name="view_type">form</field>
            <field name="view_mode">tree,form</field>
            <field name="view_id" ref="view_demo_tree"/>
        </record>


       <menuitem name="Sample Result" action="action_demo_menu" id="menu_demo_sub2" parent="menu_demo_sub1" sequence="0"/>
    </data>
</openerp>

after entering a value save the record thereby you can see the total price. thank you

1
Avatar
Zrušit
Abhishek H Menon

hope the answer is okay mos

jean44
Autor

Thank you brother ! it works.

Avatar
Serpent Consulting Services Pvt. Ltd.
Nejlepší odpověď

If I am not wrong, you have kept the return x inside for loop. Get it out of the loop and see. Thanks.

0
Avatar
Zrušit
Avatar
jean44
Autor Nejlepší odpověď

Thank you for your answer, the return is already out of the loop, I just made a mistake when I was typing the code here. Always the same problem :(

Please can you guive a simple exemple of the fields.function that illustrating how to use them. Thank you.

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
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 Svenska ภาษาไทย 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