Skip to Content
Odoo Menu
  • Sign in
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Approvals
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage Distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help

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

  • CRM
  • e-Commerce
  • Accounting
  • Inventory
  • PoS
  • Project
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
Help

why compute method not triggered?

Subscribe

Get notified when there's activity on this post

This question has been flagged
many2onecomputedisplayname
1 Reply
8870 Views
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
Discard
hesham@elmahdy.info
Author

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

Avatar
Ivan
Best Answer

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
Discard
hesham@elmahdy.info
Author

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!

Sign up
Related Posts Replies Views Activity
why I can't delete records of another module by the compute function in a field?
many2one compute
Avatar
0
Aug 19
4344
Get integer values from Many2one field, and then compute it all Solved
many2one compute
Avatar
1
Dec 15
7068
compute many2one from custom model's Solved
many2one compute 13.0
Avatar
1
Oct 20
8687
Related two Many2one fields in the same line
many2one compute relation stock.move.line
Avatar
Avatar
1
Feb 23
3240
Is it possible to populate a One2Many field with content from 2 different models? Solved
v8 many2one one2many compute
Avatar
Avatar
1
Mar 15
5925
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة 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 is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

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