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

How to override an overrided method

Odebírat

Get notified when there's activity on this post

This question has been flagged
createmethodoverrideifOdoo13
3 Odpovědi
14940 Zobrazení
Avatar
Benjamin Cherpas

Hi,


I'd like to remove IF statement (just under # OVERRIDE) from the following method which is in AccountMove class in Odoo addons:



@api.model_create_multi
def create(self, vals_list):
# OVERRIDE
if any('state' in vals and vals.get('state') == 'posted' for vals in vals_list):
raise UserError(_('You cannot create a move already in the posted state. Please create a draft move and post it after.'))

vals_list = self._move_autocomplete_invoice_lines_create(vals_list)

moves = super(AccountMove, self).create(vals_list)

# Trigger 'action_invoice_paid' when the invoice is directly paid at its creation.
moves.filtered(lambda move: move.is_invoice(include_receipts=True) and move.invoice_payment_state in ('paid', 'in_payment')).action_invoice_paid()

return moves


The problem is when I override the method (with copy paste) and remove if any('state'...., the super statement call once more the create method and set the if statement.


How can I override this method and remove the if statement correctly?


Thanks in advance,

Regards.

2
Avatar
Zrušit
Avatar
Sudhir Arya (ERP Harbor Consulting Services)
Nejlepší odpověď

You cannot do that. You have to go into the base code and comment that out.

The other option you have is to change the state to draft in the vals and call the super method. 
When super return a recordset, just write a state to posted (res.state = 'posted').

3
Avatar
Zrušit
Avatar
Baiju KS
Nejlepší odpověď

Hi Benjamin,

If you call super, it will call the create method in AccountMove. Instead of using super() you can use models.Model.create().

Please remove this line from the code

moves = super(AccountMove, self).create(vals_list)

and Add this

return models.Model.create(self, vals_list)

Hope this helps.

3
Avatar
Zrušit
Benjamin Cherpas
Autor

Thank you for your reply. It gives me this error:

File "/usr/lib/python3/dist-packages/odoo/addons_adquat/adquat_data_import/models/import_invoices.py", line 169, in custom_create

moves = models.Model.create(vals_list[0])

TypeError: create() missing 1 required positional argument: 'vals_list'

I don't understand because I fill the method with the vals_list (dict element).

Baiju KS

Answer updated, please check now

Benjamin Cherpas
Autor

Yeees I saw last Friday and I noticed I had to add self in the create method, Thank you, you won an upvote :)

Sudhir Arya (ERP Harbor Consulting Services)

The drawback is that it will not call the create() method overrode in the any base / custom modules.

Baiju KS

He doesn't want to call super after his modification, this will call the create method directly from ORM and will skip all other create() in the object

Wahyu Alif Aldika

can i use this solution on non-orm method like _action_cancel in sale order?

Baiju KS

for non-orm methods, you can simply define that function without super() to completely override, simple monkey patching

Avatar
Annadurai
Nejlepší odpověď

Hello,

Do monkey patching technic ..!

-2
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
Where can I find CRUD source code?
create method unlink override
Avatar
Avatar
1
led 22
4521
Modify ORM create method behavior two times using inheritance [Old API] [SOLVED] Vyřešeno
create orm method override
Avatar
Avatar
1
lis 15
6825
Modify ORM create method behavior two times using inheritance [Old API]
create orm method override
Avatar
0
lis 15
13
How to override completely the create method of pos_session class? Vyřešeno
create method override super return
Avatar
1
úno 16
5895
Record does not exist or have been deleted
create method
Avatar
Avatar
1
led 19
12105
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