Skip to Content
Odoo Meniu
  • Autentificare
  • Try it free
  • Aplicații
    Finanțe
    • Contabilitate
    • Facturare
    • Cheltuieli
    • Spreadsheet (BI)
    • Documente
    • Semn
    Vânzări
    • CRM
    • Vânzări
    • POS Shop
    • POS Restaurant
    • Abonamente
    • Închiriere
    Site-uri web
    • Constructor de site-uri
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Lanț Aprovizionare
    • Inventar
    • Producție
    • PLM
    • Achiziție
    • Maintenance
    • Calitate
    Resurse Umane
    • Angajați
    • Recrutare
    • Time Off
    • Evaluări
    • Referințe
    • Flotă
    Marketing
    • Social Marketing
    • Marketing prin email
    • SMS Marketing
    • Evenimente
    • Automatizare marketing
    • Sondaje
    Servicii
    • Proiect
    • Foi de pontaj
    • Servicii de teren
    • Centru de asistență
    • Planificare
    • Programări
    Productivitate
    • Discuss
    • Aprobări
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Aplicații Terțe Odoo Studio Platforma Odoo Cloud
  • Industrii
    Retail
    • Book Store
    • Magazin de îmbrăcăminte
    • Magazin de Mobilă
    • Magazin alimentar
    • Magazin de materiale de construcții
    • Magazin de jucării
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Distribuitor de băuturi
    • Hotel
    Proprietate imobiliara
    • Real Estate Agency
    • Firmă de Arhitectură
    • Construcție
    • Estate Managament
    • Grădinărit
    • Asociația Proprietarilor de Proprietăți
    Consultanta
    • Firma de Contabilitate
    • Partener Odoo
    • Agenție de marketing
    • Law firm
    • Atragere de talente
    • Audit & Certification
    Producție
    • Textil
    • Metal
    • Mobilier
    • Mâncare
    • Brewery
    • Cadouri corporate
    Health & Fitness
    • Club Sportiv
    • Magazin de ochelari
    • Centru de Fitness
    • Wellness Practitioners
    • Farmacie
    • Salon de coafură
    Trades
    • Handyman
    • IT Hardware and Support
    • Asigurare socială de stat
    • Cizmar
    • Servicii de curățenie
    • HVAC Services
    Altele
    • Organizație nonprofit
    • Agenție de Mediu
    • Închiriere panouri publicitare
    • Fotografie
    • Închiriere biciclete
    • Asigurare socială
    Browse all Industries
  • Comunitate
    Învăță
    • Tutorials
    • Documentație
    • Certificări
    • Instruire
    • Blog
    • Podcast
    Empower Education
    • Program Educațional
    • Scale Up! Business Game
    • Visit Odoo
    Obține Software-ul
    • Descărcare
    • Compară Edițiile
    • Lansări
    Colaborați
    • Github
    • Forum
    • Evenimente
    • Translations
    • Devino Partener
    • Services for Partners
    • Înregistrează-ți Firma de Contabilitate
    Obține Servicii
    • Găsește un Partener
    • Găsiți un contabil
    • Meet an advisor
    • Servicii de Implementare
    • Referințe ale clienților
    • Suport
    • Actualizări
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Obține un demo
  • Prețuri
  • Ajutor

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Contabilitate
  • Inventar
  • PoS
  • Proiect
  • MRP
All apps
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Suport

why compute method not triggered?

Abonare

Primiți o notificare când există activitate la acestă postare

Această întrebare a fost marcată
many2onecomputedisplayname
1 Răspunde
8874 Vizualizări
Imagine profil
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
Imagine profil
Abandonează
hesham@elmahdy.info
Autor

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

Imagine profil
Ivan
Cel mai bun răspuns

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
Imagine profil
Abandonează
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!

Înscrie-te
Related Posts Răspunsuri Vizualizări Activitate
why I can't delete records of another module by the compute function in a field?
many2one compute
Imagine profil
0
aug. 19
4347
Get integer values from Many2one field, and then compute it all Rezolvat
many2one compute
Imagine profil
1
dec. 15
7071
compute many2one from custom model's Rezolvat
many2one compute 13.0
Imagine profil
1
oct. 20
8688
Related two Many2one fields in the same line
many2one compute relation stock.move.line
Imagine profil
Imagine profil
1
feb. 23
3240
Is it possible to populate a One2Many field with content from 2 different models? Rezolvat
v8 many2one one2many compute
Imagine profil
Imagine profil
1
mar. 15
5926
Comunitate
  • Tutorials
  • Documentație
  • Forum
Open Source
  • Descărcare
  • Github
  • Runbot
  • Translations
Servicii
  • Hosting Odoo.sh
  • Suport
  • Actualizare
  • Custom Developments
  • Educație
  • Găsiți un contabil
  • Găsește un Partener
  • Devino Partener
Despre Noi
  • Compania noastră
  • Active de marcă
  • Contactați-ne
  • Locuri de muncă
  • Evenimente
  • Podcast
  • Blog
  • Clienți
  • Aspecte juridice • Confidențialitate
  • Securitate
الْعَرَبيّة 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 este o suită de aplicații de afaceri open source care acoperă toate nevoile companiei dvs.: CRM, comerț electronic, contabilitate, inventar, punct de vânzare, management de proiect etc.

Propunerea de valoare unică a Odoo este să fie în același timp foarte ușor de utilizat și complet integrat.

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