0
votes

enter image description hereI have two models weather_location.weather_location and current_weather.current_weather. In weather_location.weather_location there is One2many field and current_weather.current_weather there is Many2one field. Now, I want to show the fields in kanban view of weather_location.weather_location which are declared in current_weather.current_weather.. Here, Attach the code which i tried:

class location(models.Model):
    _name = 'location.location'

    name = fields.Char(string="City Name")
    location_ids = fields.One2many('weather.weather', 
                    'weather_id', string="Weather Details")
api_address = "http://api.openweathermap.org/data/2.5/weather?appid=6784429f5eff661309aaa5280a143f97&q="

def get_weather_data(self):
    url = self.api_address + self.name
    json_data = requests.get(url).json()
    formatted_data = json_data['weather'][0]['main'] 
    formatted_data1 = json_data['main']['temp']
    formatted_data2 = json_data['main']['temp_min']
    formatted_data3 = json_data['main']['temp_max']
    formatted_data4 = json_data['main']['humidity']
    self.env['weather.weather'].create(
                {'weather_id':self.id,
                 'main':formatted_data,
                 'temp':formatted_data1,
                 'temp_min':formatted_data2,
                 'temp_max':formatted_data3,
                 'humidity':formatted_data4,
                })
class current_weather(models.Model):
    _name = 'weather.weather'

    weather_id = fields.Many2one('location.location', 
            string="Weather",)
    color = fields.Integer()
    main = fields.Char(string="Main")
    temp = fields.Float(string="Temperature")
    temp_min = fields.Float(string="Minimum Temperature")
    temp_max = fields.Float(string="Maximum Temperature")
    humidity = fields.Float(string="Humidity")

.xml file(kanban view):

<record model="ir.ui.view" id="current_location_Kanban">
      <field name="name">current_weather kanban</field>
      <field name="model">location.location</field>
      <field name="type">kanban</field>
      <field name="arch" type="xml">
        <kanban default_group_by="name">
          <field name="name"/>
                <templates>
                    <t t-name="kanban-box">
                        <div t-attf-class="oe_kanban_content">
                            Main:
                            <!-- <field name="main"/> -->
                            <br/>
                            Temperature:
                            <!-- <field name="temp"/> -->
                            <br/>
                            Minimum Temperature:
                            <!-- <field name="temp_min"/> -->
                            <br/>
                            Maximum Temperature
                            <!-- <field name="temp_max"/> -->
                            <br/>
                            Humidity:
                            <!-- <field name="humidity"/> -->
                        </div>
                    </t>
                </templates>
        </kanban>
      </field>
    </record>

By using this only labels are shown not their values. How to access their values

2
Show the screenshot of that kanban view @user_123Navi
Check the edited one. @Naveenuser_123
Remove the comments for the fields@user_123Navi
If remove then it gives error(i.e. field_name does not exist)@Naveenuser_123
show me weather_location.weather_location model @user_123Navi

2 Answers

0
votes
<record model="ir.ui.view" id="current_location_form_view">
  <field name="name">current_weather form</field>
  <field name="model">location.location</field>
  <field name="arch" type="xml">
    <form string="Idea Form">
      <header>
          <button string="Get Weather Data" type="object" name="get_weather_data" class="oe_highlight"/>
      </header>
      <sheet>
          <group>
              <field name="name"/>
          </group>
          <notebook>
            <page string="Weather Deatils">
                <field name="location_ids">
                  <tree string="Weather Tree">
                    <field name='main'/>
                    <field name='temp'/>
                    <field name='temp_min'/>
                    <field name='temp_max'/>
                    <field name='humidity'/>
                  </tree>
                </field>
            </page>
          </notebook>
      </sheet>
    </form>
  </field>
</record>
0
votes
 I have number of fields main,temp,temp_min etc. 
  @api.model
    def getKanbanRecord(self, records, o2m_dataset):
        updated_record = []
        for record in records:
            for key, value in o2m_dataset.items():
                ids = record[value["field_name"]]
                res = self.env[value["model"]].browse(ids)
                res_fields = value["fields"]
                o2m_data = res.search_read([('id', 'in', ids)], res_fields)
                record[value["field_name"]] = o2m_data
            updated_record.append(record)
        return updated_record