[WIP] event_weather: created base model and views with api conection

This commit is contained in:
Juan Pablo Ticse
2023-09-21 16:12:34 +00:00
parent 43f43a0ff3
commit ad889e6e9f
5 changed files with 78 additions and 0 deletions

View File

@@ -0,0 +1 @@
from . import models

View File

@@ -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,
}

View File

@@ -0,0 +1 @@
from . import weather

View File

@@ -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,
})

View File

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="event_view_event_form_inherit" model="ir.ui.view">
<field name="name">event.view.event.form.inherit</field>
<field name="model">event.event</field>
<field name="inherit_id" ref="event.view_event_form" />
<field name="arch" type="xml">
<xpath expr="//group/field[@name='tag_ids']" position="after">
<field name="weather"/>
<field name="lat"/>
<field name="long"/>
</xpath>
<xpath expr="//div[hasclass('oe_button_box')]/button" position="after">
<button name="get_weather" type="object" class="oe_stat_button" icon="fa-sun" help="Weather location">
<field name="weather" string="Weather"/>
</button>
</xpath>
</field>
</record>
</odoo>