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

Model Name in Fleet module?

Subscribe

Get notified when there's activity on this post

This question has been flagged
fleetmodulecomputed-fields
2 Replies
5211 Views
Avatar
7heJumpeR

I want to create Model (car) name like, Telsa / Model X, and I found this piece of code of Fleet module doing that.

FleetVehicleModel class (models.Model) 
_name = 'fleet.vehicle.model'
_description = 'Model of a vehicle'
_order = 'desc'

name = fields.Char ('Model name', required = True)
brand_id = fields. Many2one ('fleet.vehicle.model.brand', 'Make', required = True, help = 'Make of the vehicle')
vendors fields.Many2many = ('res.partner', 'fleet_vehicle_model_vendors',' model_id '' partner_id ', string =' Vendors')
image = fields.Binary (related = 'brand_id.image', string = "Logo", readonly = False)
image_medium = fields.Binary (related = 'brand_id.image_medium', string = "Logo (medium) ",
image_small = fields.Binary (related = 'brand_id.image_small', string = "Logo (small)", readonly = False)

@ api.multi
@ api.depends ('name', 'brand_id')
def name_get (self):
res = []
for record in self:
name = record.name
if record.brand_id.name:
name = record.brand_id.name + '/' + name
res.append ((record.id, name))
return res

I do not understand how this code works when I choose the model then press Save button, it will create a new name under the form "Brand / Model" and replace the old name I filled.
And I did not see any 'computed field' in this model.
I figure out by 'print (res)', but I do not understand how this can link 'record.id' in 'res []' to find the new name.
I also can not find any new fields in Database too.


I will appreciate if someone can explain it.
Many thanks

0
Avatar
Discard
Avatar
Niyas Raphy (Walnut Software Solutions)
Best Answer

Hi,

What is your doubt about ? Is it about the name_get function defined ? The methods is called by Odoo core itself, probably you  will never end up calling those by yourself or not needed to have a compute field for that. Those methods are called by some widgets like many2one to get the display name of the record.


Thanks

1
Avatar
Discard
7heJumpeR
Author

In short, I just want to know Where is list res[] in get_name func stored?

Avatar
7heJumpeR
Author Best Answer

Well, I want to create a name of a car in the form like "Model/Brand", e.g: ModelX/Telsa. I call this 'formed name'.

Generally, I will create a field: 

Car_name = fields.Char(computed='get_name')

brand_id = fields.Many2one('car.brand')

model_id = fields.Many2one('car.model')

then I will define a 'computed function' to create 'car_name' like I want.

@api.depends('brand_id', 'model_id')

def get_name(self):

car_name = str(brand_id.name) + '/' + str(model_id.name)

then, I can show car_name in my tree.view or form.view. 

It is ok if I do like that.

BUT, when I read the code in Fleet module, there isn't a 'computed field' (to form the name like I want).

If you read name_get func in Fleet code (like, I quoted above), they just use a list res[], then stored the formed name and the id of the record. Then the 'formed name' appears in the tree.view or form.view after I press the Save button.

I just print the list 'res[]', and it stored the id and the 'formed name' as: [(1, ModelX/Telsa),(2, Vios/Toyota)....]

I just dont understand how they can call the formed name through 'res' list only by the id of the record. I checked in the SQL but cant find any field store 'formed name'.

In short, I just want to know Where is list res[] in get_name func stored?

0
Avatar
Discard
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
computed field doesnt work with a domain
fleet computed-fields v15
Avatar
0
Apr 24
2239
Update fleet vehicule
fleet module update
Avatar
Avatar
1
Feb 19
3798
fleet management offline
fleet
Avatar
Avatar
Avatar
2
Oct 25
575
ValueError: forbidden opcode(s) in 'lambda': STORE_ATTR
computed-fields
Avatar
Avatar
1
Jun 25
16745
Make stored compute filed recompute after changing it logic but not depedencies.
computed-fields
Avatar
Avatar
Avatar
Avatar
3
Apr 25
7316
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