mirror of
https://gitlab.com/hibou-io/hibou-odoo/suite.git
synced 2025-01-20 12:37:31 +02:00
[WIP] event_weather: created base model and views with api conection
This commit is contained in:
1
event_weather/__init__.py
Normal file
1
event_weather/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import models
|
||||
11
event_weather/__manifest__.py
Normal file
11
event_weather/__manifest__.py
Normal 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,
|
||||
}
|
||||
1
event_weather/models/__init__.py
Normal file
1
event_weather/models/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import weather
|
||||
43
event_weather/models/weather.py
Normal file
43
event_weather/models/weather.py
Normal 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,
|
||||
})
|
||||
|
||||
|
||||
|
||||
22
event_weather/views/weather_views.xml
Normal file
22
event_weather/views/weather_views.xml
Normal 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>
|
||||
Reference in New Issue
Block a user