diff --git a/event_weather/__init__.py b/event_weather/__init__.py new file mode 100644 index 00000000..0650744f --- /dev/null +++ b/event_weather/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/event_weather/__manifest__.py b/event_weather/__manifest__.py new file mode 100644 index 00000000..beb9043c --- /dev/null +++ b/event_weather/__manifest__.py @@ -0,0 +1,11 @@ +{ + 'name': 'ClientTest Weather Event', + 'author': 'JP', + 'version': '16.0.0.0.0', + 'depends': ['event'], + 'data': [ + 'views/weather_views.xml', + ], + 'installable': True, + 'application': True, +} diff --git a/event_weather/models/__init__.py b/event_weather/models/__init__.py new file mode 100644 index 00000000..c6c867d0 --- /dev/null +++ b/event_weather/models/__init__.py @@ -0,0 +1 @@ +from . import weather diff --git a/event_weather/models/weather.py b/event_weather/models/weather.py new file mode 100644 index 00000000..594cd30e --- /dev/null +++ b/event_weather/models/weather.py @@ -0,0 +1,43 @@ +from odoo import models, fields, _, api +from odoo.exceptions import ValidationError +import requests +import json + +class Weather(models.Model): + _inherit = 'event.event' + + long = fields.Char('Longitude') + lat = fields.Char('Latitude') + weather = fields.Selection([ + ('sunny', 'Sunny'), + ('windy', 'Windy'), + ('cloudy', 'Cloudy'), + ('rainy', 'Rainy'), + ]) + + def get_weather(self): + partner = self.address_id + result = partner._geo_localize(partner.street, + partner.zip, + partner.city, + partner.state_id.name, + partner.country_id.name) + latitude = result[0] + longitude = result[1] + + api_key = 41eae7153956aa5aa0501ee9681bfdec + + api_url = "https://api.openweathermap.org/data/2.5/weather?lat={latitude}&lon={longitude}&appid={api_key}" + api_response = requests.get(api_url) + response_content = api_response.content + response_object = json.loads(response_content) + # api_weather = response_object.weather.main + raise ValidationError(str(response_object)) + + self.write({ + 'lat':api_weather, + 'long':api_weather, + }) + + + diff --git a/event_weather/views/weather_views.xml b/event_weather/views/weather_views.xml new file mode 100644 index 00000000..2a89c489 --- /dev/null +++ b/event_weather/views/weather_views.xml @@ -0,0 +1,22 @@ + + + + + event.view.event.form.inherit + event.event + + + + + + + + + + + + + +