【问题标题】:How to view one2many fields in kanban view?如何在看板视图中查看 one2many 字段?
【发布时间】:2018-03-27 06:51:02
【问题描述】:

我有两个模型 weather_location.weather_locationcurrent_weather.current_weatherweather_location.weather_location 有 One2many 字段,current_weather.current_weather 有 Many2one 字段。现在,我想在 weather_location.weather_location 的看板视图中显示在 current_weather.current_weather 中声明的字段。 在这里,附上我尝试过的代码:

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 文件(看板视图):

<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>

通过使用它只显示标签而不显示它们的值。如何访问它们的值

【问题讨论】:

  • 显示该看板视图的屏幕截图@user_123
  • 检查已编辑的。 @Naveen
  • 删除字段@user_123的cmets
  • 如果删除则给出错误(即 field_name 不存在)@Naveen
  • 显示weather_location.weather_location模型@user_123

标签: odoo odoo-10


【解决方案1】:
<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>

【讨论】:

  • Form_view@Naveen
  • 看我的回答,你一定会得到你需要的东西@user_123
  • 我没试过那个模块,但它会满足你的需要@user_123
  • 得到答案了吗?@user_123
【解决方案2】:
 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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-10
    • 2018-04-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多