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
    • Textile
    • Kov
    • Nábytek
    • Jídlo
    • Brewery
    • Korporátní dárky
    Zdraví a fitness
    • Sportovní klub
    • Prodejna brýli
    • Fitness Centrum
    • Wellness praktikové
    • Lékárna
    • Kadeřnictví
    Transakce
    • Údržbář
    • IT hardware a podpora
    • 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
    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

why compute method not triggered?

Odebírat

Get notified when there's activity on this post

This question has been flagged
many2onecomputedisplayname
1 Odpovědět
8858 Zobrazení
Avatar
hesham@elmahdy.info

Here is what I want to do:

in the invoice screen, when creating new invoice, we select partner (customer or supplier). when you start typing characters the system bring partner name starting with those characters. I want the system to search not only name but also partner_code (this column I added to res.partner). So, the solution I though about is to override the display_name which is a compute field to make ti include both partner_code and name, instead of name only. i linked the display_name field with a compute method. But, my problem is that compute method is not triggered at all.

 

Please help me find out why it is not triggered.

 

here is the code:

from openerp import fields, models, api, _ # TODO: make the 'Code and Name' labels in Partner and Product dynamic calling a method so the text can be translatable # -------------------------- Product # noinspection PyPep8Naming class product_template(models.Model): #_name = 'product.template' # this is Odoo object product.product which is related to table product_product _inherit = 'product.template' # TODO: add default_code to tree view product_supplier_code = fields.Char(string=_("Product Supplier Code"), help=_("Product Code that your supplier uses")) product_brand = fields.Char(string=_("Brand Name")) @api.one @api.onchange('default_code') def make_pc_uppercase(self): if (self.default_code): self.default_code = (self.default_code).upper() # TODO: in product module, upon change check uniqueness @api.onchange('product_supplier_code') def make_spc_uppercase(self): if (self.product_supplier_code): self.product_supplier_code = (self.product_supplier_code).upper() class product_product(models.Model): #_name = 'product.product' _inherit = 'product.product' _sql_constraints = [ ('default_code','unique(default_code)',_('Product Code Already Exists !!')) ] class res_partner(models.Model): # _name="res.partner" _inherit = "res.partner" partner_code = fields.Char(string="Partner Code", help=_("Partner (Customer / Supplier) Code")) display_name = fields.Char(string="Name", compute='_display_name_compute') #, search='_search_partner') _sql_constraints = [ ('partner_code','unique(partner_code)',_('Partner Code Already Exists !!')) ] # def _search_partner(self): # return "00000000000000000" # # what? @api.one @api.constrains @api.depends('name', 'partner_code') # this definition is recursive def _display_name_compute(self): self.display_name = self.partner_code + ' - ' + self.name print "===========================================================" # if self.partner_code: # self.display_name = self.partner_code + ' / ' + self.display_name + ' / ' + self.name # else: # self.display_name = '-' + self.name + ' / ' @api.one @api.onchange('partner_code') # @api.constrains('partner_code') def onchange_partner_code(self): if (self.partner_code): self.partner_code = (self.partner_code).upper() records = self.search([('partner_code', '=', self.partner_code)]) print "==========================================================::::::: ", len(records) if len(records) > 1: # if only 1 record is found means we are ok. we just found the record we are creating. raise Warning(_("This Partner Code already exists!")) # if raise XXX is called the method will exit from here and will not continue return True else: print "partner code is still FALSE :::::::::::::::::::::::::::::::::::::" # def redirect_partner_form(self, cr, uid, partner_id, context=None): # search_view = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'base', 'odootec_view_res_partner_filter') # value = { # 'domain': "[]", # 'view_type': 'form', # 'view_mode': 'form,tree', # 'res_model': 'res.partner', # 'res_id': int(partner_id), # 'view_id': False, # 'context': context, # 'type': 'ir.actions.act_window', # 'search_view_id': search_view and search_view[1] or False # } # return value

 

-1
Avatar
Zrušit
hesham@elmahdy.info
Autor

Sorry code is scrambled. I posted another question regarding that.

Avatar
Ivan
Nejlepší odpověď

The methods that you should override is name_get and name_search.

name_get will determine what text to display when a record is selected, say in a many2one field.  If not overriden the default will be the _rec_name attribute of the model.  If not specified, the default will be taking the 'name' field.  If not defined, the default will be spewing something like 'model.name,9' where model.name is the model name (e.g. res.partner) and 9 is the database ID (e.g. 'res.partner, 123')

name_search will determine how a string entered to the many2one field will be searched against the records.  Normally, it will search only the field designated as 'name', but you can add additional search criteria such as the 'partner_code' column that you have added.

Note that name_search does not require name_get to be changed to work.  Meaning you can just implement change in name_search alone without changing the displayed name.

You can find example of those methods overriden in product.product model (odoo/addons/product/product.py).  It is still written in v7 API though.

0
Avatar
Zrušit
hesham@elmahdy.info
Autor

as per 8.8.0 docs name_get method is deprecated, and the alternative is to override display_name field as compute. But my problem is the compute method is not triggered

Ivan

I've commented in your comment in another questions. From the docs that I've read (lastest is dated 15 Feb 2015), name_get is still the underlying method called by display_name.

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
why I can't delete records of another module by the compute function in a field?
many2one compute
Avatar
0
srp 19
4330
Get integer values from Many2one field, and then compute it all Vyřešeno
many2one compute
Avatar
1
pro 15
7050
compute many2one from custom model's Vyřešeno
many2one compute 13.0
Avatar
1
říj 20
8673
Related two Many2one fields in the same line
many2one compute relation stock.move.line
Avatar
Avatar
1
úno 23
3233
Is it possible to populate a One2Many field with content from 2 different models? Vyřešeno
v8 many2one one2many compute
Avatar
Avatar
1
bře 15
5917
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