Skip to Content
Menu
This question has been flagged
2 Replies
1777 Views

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>


Avatar
Discard
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.



Avatar
Discard
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).

Avatar
Discard
Related Posts Replies Views Activity
1
Aug 19
9187
1
Mar 15
3598
2
Sep 22
7895
2
Apr 22
2459
0
Jul 21
5322