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

tree view for one2Many not populating

Subscribe

Get notified when there's activity on this post

This question has been flagged
one2manyone2many_list
2 Replies
3859 Views
Avatar
Elisha Wambiji

I have a tree view to show logs, but this logs come from a third party solution. I created a transient model to hold the logs. I compute the logs on the fly but the tree is not get populated with the data, nor is the database been updated. 


class VehicleLogs(models.TransientModel):
_name = 'vehicle.logs'
name = fields.Char()
timestamp = fields.Datetime()
speed = fields.Integer()
over_speed = fields.Boolean()
power_wire = fields.Boolean()
signal_wire = fields.Boolean()
vehicle_id = fields.Many2one('vehicle')

class Vehicles(models.Model):
_inherit = 'vehicle'
vehicle_log_ids = fields.One2many('vehicle.logs', 'vehicle_id', compute='_compute_vehicle_logs')

def format_data(self, data):
res = []
data = data[0][:1]
for _ in data:
vals = {'name': _['device_timestamp'], 'speed': int(_['speed']),
'over_speed': True if int(_['speed']) > 84 else False,
'power_wire': _['p_wire'],
'vehicle_id': self.id,
'signal_wire': _['s_wire']}
res.append((0, 0, vals))
return res

@api.multi
def _compute_vehicle_logs(self):
for vehicle in self:
traccar_id = vehicle.traccar_id
_from = (datetime.datetime.now() - datetime.timedelta(hours=1))
_to = datetime.datetime.now()
_from = (datetime.datetime.now() - datetime.timedelta(hours=6))

base_url = self.vendor_id.traccar_url
traccar_username = self.vendor_id.traccar_username
traccar_password = self.vendor_id.traccar_password

res = self.env['report.device_reports.device_report'].get_traccar_positions(base_url, traccar_username,
traccar_password, traccar_id,
_from,
_to)
values = self.format_data(res)
vehicle.vehicle_log_ids = values




<record model="ir.ui.view" id="view_vehicle_form_ext">
<field name="name">vehicle.form.ext</field>
<field name="model">vehicle</field>
<field name="inherit_id" ref="vehicles.view_vehicle_form"/>
<field name="arch" type="xml">
<xpath expr="//notebook" position="inside">
<page string="Device Logs" autofocus="autofocus">
<field name="vehicle_log_ids">
<tree default_order="timestamp desc">
<field name="timestamp"/>
<field name="speed"/>
<field name="over_speed"/>
<field name="power_wire"/>
<field name="signal_wire"/>
</tree>
</field>
</page>
</xpath>
</field>
</record>


0
Avatar
Discard
Avatar
Elisha Wambiji
Author Best Answer

that is why am using it. I dont want to keep storing this data but just have a way of displaying when a user clicks on the record.



0
Avatar
Discard
Avatar
Gleb
Best Answer

 class odoo.models.TransientModel
Model super-class for transient records, meant to be temporarily persistent, and regularly vacuum-cleaned.

If you want to use field you need to change class from class VehicleLogs(models.TransientModel) to class VehicleLogs(models.Model).

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
how get value from one2many field? Solved
one2many one2many_list
Avatar
Avatar
1
Aug 19
11348
How to add records to one2many_list either by creating them, or selecting them ? Solved
one2many selection one2many_list
Avatar
Avatar
1
Mar 15
5417
Custom functionality with One2many field
one2many one2many_list v18 CommunityEdition
Avatar
Avatar
1
May 25
1977
how pass value to on2many field from parent form via context
one2many
Avatar
Avatar
1
Jan 25
2772
How to make tree view place last entered field on the top of tree view? What is the difference between editable="top" and editable="bottom"?
one2many
Avatar
Avatar
Avatar
2
Sep 22
10480
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