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í
    Food & Hospitality
    • Bar a Pub
    • Restaurace
    • Fast Food
    • Guest House
    • Distributor nápojů
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architektonická firma
    • Stavba
    • Správa nemovitostí
    • Zahradnictví
    • Asociace vlastníků nemovitosti
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketingová agentura
    • Právník
    • Akvizice talentů
    • Audit a certifikace
    Výroba
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Korporátní dárky
    Zdraví a fitness
    • Sportovní klub
    • Prodejna brýli
    • Fitness Centrum
    • Wellness praktikové
    • Lékárna
    • Kadeřnictví
    Trades
    • Údržbář
    • IT hardware a podpora
    • Solar Energy Systems
    • Výrobce obuvi
    • Úklidové služby
    • HVAC Services
    Others
    • Nonprofit Organization
    • 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

[v9 community] override the write function

Odebírat

Get notified when there's activity on this post

This question has been flagged
writeexpenseoverridev9
1 Odpovědět
3810 Zobrazení
Avatar
Korund

Hello there,

I need to override the write function and from inside it, to write in an other record (after the current record has been saved). This code creates a "maximal recursion depth exceeded" because the write function is calling itself from the write function. I read on stark overflow that you can get around this by doing something like this: 

@api.multi
def write(self, vals):
     if 'custom_field' not in vals:
         vals['custom_field'] = 37
     return super(self).write(vals)

but this only writes in the current record. I need the values of some other records (of the same model -hr.expense-) to be updated as well. If using "update" instead of "write, it doesn't update the field total amount. Here is my code.

How can i fix this? 


[infos: v9 community, module concerned: hr. expense]

@api.multi    
def write(self, vals):
     self.update_other_dest_ids()
     value = super(Expenses, self).write(vals)
     self.search_and_modify_connected_travel()
     for tagx in self.expenses_summary_ids
         if tagx.time is not '24:00':
             exps = self.find_all_expenses_on_same_day(tagx.day)
             for each in exps:
                each._update_unit_price()
     return value


@api.one    
@api.depends('expenses_summary_ids.amount_due')
def _update_unit_price(self):
    if self.expenses_calculator:
         table_sum = 0.0
         for expense in self:
             for line in expense.expenses_summary_ids:
                 table_sum += line.amount_due
                 if self.calculated_unit_amount != table_sum:
                     self.write({'calculated_unit_amount' : table_sum})
                 if self.unit_amount != table_sum:
                     self.write({'unit_amount' : self.calculated_unit_amount})
                    
0
Avatar
Zrušit
Avatar
Esther Martín
Nejlepší odpověď

if you are using api.one you dont need the "for expense in self:"

@api.one    
@api.depends('expense_summary_ids','expenses_summary_ids.amount_due')
def _update_unit_price(self):
    if self.expenses_calculator:
         table_sum = 0.0
         for line in self.expenses_summary_ids:
             table_sum += line.amount_due
             if self.calculated_unit_amount != table_sum:
                 self.calculated_unit_amount = table_sum
             if self.unit_amount != table_sum:
                 self.unit_amount = self.calculated_unit_amount
maybe calculated_unit_amount should be on the depends too.

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
If field is selected on of the other 6 fields should be selected to
write override
Avatar
Avatar
1
zář 18
3452
"Write" called twice on update, once on creation, and "Create" never called?
write override
Avatar
1
bře 15
6013
[SOLVED] How to ignore SUPER? (new API)
write super v9
Avatar
Avatar
Avatar
5
lis 22
6283
Override v7 onchange and add extra parameters
onchange override v9
Avatar
1
bře 16
4359
Odoo v9: Cannot pay Expense
accounting expense v9
Avatar
0
led 16
3767
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