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

Override an inherited function

Odebírat

Get notified when there's activity on this post

This question has been flagged
2 Odpovědi
13096 Zobrazení
Avatar
SonnyV

Hello guys,

I'm trying to create an extension to the membership module. (I have called it x_membership)

Now I need to inherit a write and create function from the membership module.

The problem is that this function inherits account_invoice_line. So after a lot of trying and experimenting, I inherited the account_invoice_line in my x_membership module. This works, but now whenever I create a subscription, the method gets called twice, once from my module x_membership and once from the default membership module.

So my question is: how can I override the membership modules' create function? This function is in the membership.py under class account_invoice_line(osv.osv): _inherit='account.invoice.line' def write(......): res=super(account_invoice_line, self).write(.....) .......

I don't know how to tell odoo to override that method, because at this point I copied the entire account_invoice class from membership. But this calls super account invoice. I need it to be membership_account_invoice, but I don't know what name/syntax to use for this to happen.

The following is a simple image to try and clarify my question.
http://i.imgur.com/xFUvPSJ.png 

Thanks in advance, guys.

Sonny

0
Avatar
Zrušit
SonnyV
Autor

@Ivan

I do want to call the parent's write method, but I don't want the membership module to also call the account_invoice_line's write method. Because now whenever I create a new membership, the write method gets called in membership and in x_membership, resulting in two added lines, while I only expect one line.

I'm not entirely sure if my x_membership module depends on membership. In __openerp__.py I have depends : ['membership'] though.

I'm fairly new too odoo and am not really experienced with the inheritance and dependancy-tree.

EDIT: I don't have enough karma, so I cannot comment to your comment :(

EDIT2: Is it possible to remove a line from the database? Since the membership module calls a create on membership.membership_line. And I only get one invoice, but two membership_lines. SO if I'm able to say remove the member_line created from the membership module before creating a new using x_membership, my error will be gone. Another workaround I was considering is to create a new table x_membership.membership_line and only show this one instead the membership.membership_lines data. But I'd like to have this as my last resort

Avatar
Fei Chen
Nejlepší odpověď

Below example modified the "create" method ONLY in specific module( stock module for example). Note: the specific module could be at any position of the inherit chain. It doesn't matter any other modules also override that method.

The key point is "ORIGIN_Company.create = MY_Company.create". Hope this help you!


from odoo.addons.stock.models.res_company import Company as ORIGIN_Company
class MY_Company:
     def create(self, vals):
        # my code
​ res = super(ORIGIN_Company, self).create(vals)
# my code
return res 
ORIGIN_Company.create = MY_Company.create
3
Avatar
Zrušit
Erbold

Thanks it worked. Just import inheritted class to override not original class

Avatar
Ivan
Nejlepší odpověď

If you don't want to call the parent's write method (which is VERY VERY dangerous, you need to basically replicate the whole function down to the method called in BaseModel), don't call the super().  But, why don't you want to call the parent's write method?

The way OpenERP inheritance works is that it will call x_membership's (assuming that it is the "last" module in the dependency tree) account.invoice.line write() method.  If it calls super(), assuming that your x_membership module depends on the membership module, it will can membership's account.invoice.line write() method.  When (I believe it will) it calls super(), it will call the parent's account.invoice.line's write method() so on and so forth until it reach orm.BaseModel's write() method.

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
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