import datetime, time
import requests, json
import random
import base64
from dateutil.relativedelta import relativedelta
from odoo import api, fields, models, _
import pytz

class tc_geofences(models.Model):
    _name = "tc_geofences"
    _description = 'GPS Geofence'
    
    name = fields.Char('Name', size=75)
    description = fields.Char('Description', size=150)
    area = fields.Text('area')
    attributes = fields.Text('Attributes')
    color = fields.Selection([
        ('green', 'Green'),
        ('red', 'Red'),
        ('blue', 'Blue'),
        ('black', 'Black'),
        ('grey', 'Grey'),
        ('yellow', 'Yellow'),
        ], 'Color', default='green', help='Color of geofence')
    hidden = fields.Boolean('Hidden')   
    company_ids = fields.Many2many('res.company', 'tc_geofences_res_company_rel', 'user_id', 'cid', string='Companies', default=lambda self: self.env.user.company_id)



    @api.model
    def create(self, vals):
        rec = super(tc_geofences, self).create(self.save(vals))
        return rec
    @api.model
    def write(self, vals):        
        rec = super(tc_geofences, self).writ(self.save(vals))
        return rec

    def save(self, vals):        
        vals["attributes"]={}
        if("color" in vals):                  
            vals["attributes"]["color"]=vals["color"]    
    
        vals["attributes"] = json.dumps(vals["attributes"])
    
        return vals
    
    def geofences(self):
        alerts_obj      =self.env['gpsmap.geofence_device']

        alerts_args    =[]
        alerts_data    =alerts_obj.search(alerts_args, offset=0, limit=None, order=None)

        #if len(alerts_data)>0:                     
            #for alerts in alerts_data:
            #    print('ALERT ====================',alerts.name)        
        
        return alerts_data

733ce353d27d430fda3f784c05e66a73f0bc3206
<mask token>


class tc_geofences(models.Model):
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>

    @api.model
    def write(self, vals):
        rec = super(tc_geofences, self).writ(self.save(vals))
        return rec

    def save(self, vals):
        vals['attributes'] = {}
        if 'color' in vals:
            vals['attributes']['color'] = vals['color']
        vals['attributes'] = json.dumps(vals['attributes'])
        return vals

    def geofences(self):
        alerts_obj = self.env['gpsmap.geofence_device']
        alerts_args = []
        alerts_data = alerts_obj.search(alerts_args, offset=0, limit=None,
            order=None)
        return alerts_data

<mask token>


class tc_geofences(models.Model):
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>

    @api.model
    def create(self, vals):
        rec = super(tc_geofences, self).create(self.save(vals))
        return rec

    @api.model
    def write(self, vals):
        rec = super(tc_geofences, self).writ(self.save(vals))
        return rec

    def save(self, vals):
        vals['attributes'] = {}
        if 'color' in vals:
            vals['attributes']['color'] = vals['color']
        vals['attributes'] = json.dumps(vals['attributes'])
        return vals

    def geofences(self):
        alerts_obj = self.env['gpsmap.geofence_device']
        alerts_args = []
        alerts_data = alerts_obj.search(alerts_args, offset=0, limit=None,
            order=None)
        return alerts_data

<mask token>


class tc_geofences(models.Model):
    _name = 'tc_geofences'
    _description = 'GPS Geofence'
    name = fields.Char('Name', size=75)
    description = fields.Char('Description', size=150)
    area = fields.Text('area')
    attributes = fields.Text('Attributes')
    color = fields.Selection([('green', 'Green'), ('red', 'Red'), ('blue',
        'Blue'), ('black', 'Black'), ('grey', 'Grey'), ('yellow', 'Yellow')
        ], 'Color', default='green', help='Color of geofence')
    hidden = fields.Boolean('Hidden')
    company_ids = fields.Many2many('res.company',
        'tc_geofences_res_company_rel', 'user_id', 'cid', string=
        'Companies', default=lambda self: self.env.user.company_id)

    @api.model
    def create(self, vals):
        rec = super(tc_geofences, self).create(self.save(vals))
        return rec

    @api.model
    def write(self, vals):
        rec = super(tc_geofences, self).writ(self.save(vals))
        return rec

    def save(self, vals):
        vals['attributes'] = {}
        if 'color' in vals:
            vals['attributes']['color'] = vals['color']
        vals['attributes'] = json.dumps(vals['attributes'])
        return vals

    def geofences(self):
        alerts_obj = self.env['gpsmap.geofence_device']
        alerts_args = []
        alerts_data = alerts_obj.search(alerts_args, offset=0, limit=None,
            order=None)
        return alerts_data

import datetime, time
import requests, json
import random
import base64
from dateutil.relativedelta import relativedelta
from odoo import api, fields, models, _
import pytz


class tc_geofences(models.Model):
    _name = 'tc_geofences'
    _description = 'GPS Geofence'
    name = fields.Char('Name', size=75)
    description = fields.Char('Description', size=150)
    area = fields.Text('area')
    attributes = fields.Text('Attributes')
    color = fields.Selection([('green', 'Green'), ('red', 'Red'), ('blue',
        'Blue'), ('black', 'Black'), ('grey', 'Grey'), ('yellow', 'Yellow')
        ], 'Color', default='green', help='Color of geofence')
    hidden = fields.Boolean('Hidden')
    company_ids = fields.Many2many('res.company',
        'tc_geofences_res_company_rel', 'user_id', 'cid', string=
        'Companies', default=lambda self: self.env.user.company_id)

    @api.model
    def create(self, vals):
        rec = super(tc_geofences, self).create(self.save(vals))
        return rec

    @api.model
    def write(self, vals):
        rec = super(tc_geofences, self).writ(self.save(vals))
        return rec

    def save(self, vals):
        vals['attributes'] = {}
        if 'color' in vals:
            vals['attributes']['color'] = vals['color']
        vals['attributes'] = json.dumps(vals['attributes'])
        return vals

    def geofences(self):
        alerts_obj = self.env['gpsmap.geofence_device']
        alerts_args = []
        alerts_data = alerts_obj.search(alerts_args, offset=0, limit=None,
            order=None)
        return alerts_data

import datetime, time
import requests, json
import random
import base64
from dateutil.relativedelta import relativedelta
from odoo import api, fields, models, _
import pytz

class tc_geofences(models.Model):
    _name = "tc_geofences"
    _description = 'GPS Geofence'
    
    name = fields.Char('Name', size=75)
    description = fields.Char('Description', size=150)
    area = fields.Text('area')
    attributes = fields.Text('Attributes')
    color = fields.Selection([
        ('green', 'Green'),
        ('red', 'Red'),
        ('blue', 'Blue'),
        ('black', 'Black'),
        ('grey', 'Grey'),
        ('yellow', 'Yellow'),
        ], 'Color', default='green', help='Color of geofence')
    hidden = fields.Boolean('Hidden')   
    company_ids = fields.Many2many('res.company', 'tc_geofences_res_company_rel', 'user_id', 'cid', string='Companies', default=lambda self: self.env.user.company_id)



    @api.model
    def create(self, vals):
        rec = super(tc_geofences, self).create(self.save(vals))
        return rec
    @api.model
    def write(self, vals):        
        rec = super(tc_geofences, self).writ(self.save(vals))
        return rec

    def save(self, vals):        
        vals["attributes"]={}
        if("color" in vals):                  
            vals["attributes"]["color"]=vals["color"]    
    
        vals["attributes"] = json.dumps(vals["attributes"])
    
        return vals
    
    def geofences(self):
        alerts_obj      =self.env['gpsmap.geofence_device']

        alerts_args    =[]
        alerts_data    =alerts_obj.search(alerts_args, offset=0, limit=None, order=None)

        #if len(alerts_data)>0:                     
            #for alerts in alerts_data:
            #    print('ALERT ====================',alerts.name)        
        
        return alerts_data
