Skip to Content
Odoo Menu
  • Prijavi
  • 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
  • Knjigovodstvo
  • Zaloga
  • PoS
  • Projekt
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
Pomoč

one2many field show possible unexisting records in view

Naroči se

Get notified when there's activity on this post

This question has been flagged
treeviewone2manyvirtual-record
1 Odgovori
2871 Prikazi
Avatar
That Guy

Hello,

Odoo V16.

Let's say that I have a new model called Characteristcs and a model ProductCharacteristics that should connect the Product with the Characteristics and contain the value for specific product for chosen characteristic. So the three models look like this:

class ProductTemplate(models.Model):
_inherit = "product.template"

product_characteristic_id = fields.One2many(
comodel_name="product.characteristic", inverse_name="product_template_id", auto_join=True
)


class Characteristics(models.Model):
_name = "characteristics"

name = fields.Char(string="Name", required=True, translate=True)
is_comparable = fields.Boolean(string="Used for Comparison", default=False)


class ProductCharacteristic(models.Model):
_name = "product.characteristic"

product_template_id = fields.Many2one("product.template")
characteristic_id = fields.Many2one("characteristics")
value = fields.Text("Value", required=True)

Now I want to show the possible characteristics on the products form view but I want to show all possible characteristics for a given product in one form/table (whatever possible) so the user does not need to click on the tree view and select a Characteristic that he wants to fill the value for (see pic):


so I get this if I only add the to the product_template view extension xml.

But I want to have this table prefilled. So when the user opens the tab with Characteristics he sees something like this:

And he'll only fill in the values for the characteristics that he wants to fill.

So the main problem is that there are no records in the ProductCharacteristic model for the product in the beginning and thus I can not show this.

So basically I need to somehow prefill the tree with all these possible values.

Can somebody guide me on where to look?

I tried overwriting the read methods (this seems too hacky), investigated the _get_view, but to no avail. Probably I'm just not finding the right method in which I should plug the virtual records so they are displayed in the form..

Would love any comments or thought on the matter :)


0
Avatar
Opusti
Avatar
Joshi Drishti
Best Answer

Hello Vasil Stoev,

You can try default_get method. The default_get method collects the default values for all the fields when creating new records.

I think this will help you.

Thanks and Regards,

Drishti Joshi

0
Avatar
Opusti
That Guy
Avtor

Thanks for the suggestion, Drishti Joshi!
The problem with default_get is that it is called only on record creation.
In my case this would mean if I create a new Characteristic I won't be able to show it on existing products if I overwrite default_get for the Product :(

Joshi Drishti

So in this case you can do one thing while creating new characteristics so you can update characteristics to all existing products.
Try once might be this will help you.

That Guy
Avtor

Yep - I can do that. But I can basically plug in the same logic in the create method of the characteristics then.
So currently I have workarounds using the read or the default_get methods but both of those workarounds create actual records (with empty values so the fields are empty in the view). But the ideal would be to not create the records if the User has not entered any values.. Still thinking on how this could be done :(
If it was an editable kanban view I could probably set some fake records and show them as a custom structure (some divs labels with forms in a t-foreach) and then somehow save them.. although this doesn't sound perfect either.

Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Prijavi
Related Posts Odgovori Prikazi Aktivnost
how to add a button in a one2many tree view Solved
treeview one2many
Avatar
Avatar
Avatar
Avatar
Avatar
4
dec. 23
18553
Display One2many field value in tree view (Odoo 9)
treeview one2many
Avatar
Avatar
1
sep. 16
8024
editable treeview without ability to add new items
treeview one2many
Avatar
0
mar. 15
4285
How to display related fields of one2many field in list view?
treeview one2many relations
Avatar
0
sep. 24
296
Remove from tree view record created with (0,0, {})
treeview one2many flag
Avatar
1
apr. 22
3714
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