You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
2.1 KiB
50 lines
2.1 KiB
# -*- coding: utf-8 -*-
|
|
################################################################################
|
|
#
|
|
# Cybrosys Technologies Pvt. Ltd.
|
|
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>).
|
|
# Author: Bhagyadev KP (odoo@cybrosys.com)
|
|
#
|
|
# This program is free software: you can modify
|
|
# it under the terms of the GNU Affero General Public License (AGPL) as
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
# License, or (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU Affero General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
#
|
|
################################################################################
|
|
import requests
|
|
from odoo import api, fields, models, _
|
|
from odoo.exceptions import ValidationError
|
|
|
|
|
|
class ResUsers(models.Model):
|
|
"""
|
|
Extends the 'res.users' model to include additional fields related to
|
|
weather information.
|
|
"""
|
|
_inherit = "res.users"
|
|
|
|
api_key = fields.Char(string='API Key', help="API key from OpenWeatherMap")
|
|
location_set = fields.Selection(selection=[
|
|
('auto', 'Use Browser Location'),
|
|
('manual', 'Manual Location'),
|
|
], string="Set Location", default='auto',
|
|
help="Setting and managing locations")
|
|
city = fields.Char(string='City', help="City of the user")
|
|
|
|
@api.constrains('city')
|
|
def _check_city(self):
|
|
"""Checking the city valid or not"""
|
|
for rec in self:
|
|
if rec.api_key:
|
|
url = f'https://api.openweathermap.org/data/2.5/weather?q={rec.city}&appid={rec.api_key}'
|
|
city_check = requests.get(url, timeout=20).json()
|
|
if city_check['cod'] != 200:
|
|
raise ValidationError(_(city_check['message']))
|
|
|