当用户在表单中选择燃料类型时,单价将自动显示所选相应燃料类型的整数值。例如,当用户选择petroleum
时,0.87
(货币单位为美元)的值应自动显示在单价字段中。你知道吗
下面是我为电台注册创建的类的代码
# Fuel Station register Class
class fleet_fuel_stn_reg(osv.Model):
_name = 'fleet.fuel.station.reg'
_description = 'Contains fuel station details to register'
_columns = {
'station':fields.char('Station Name'),
# 'partner':fields.many2one('fleet.partner','Partner', required=True),
'location':fields.char('Location', help='Location of the vehicle (garage, ...'),
'fuel_type': fields.selection([('petroleum', 'Petroleum'), ('diesel', 'Diesel'), ('kerosene', 'Kerosene')], 'Fuel Type', help='Fuel Used by the vehicle'),
'stocklevel':fields.float('Stock Level'),
'unit':fields.selection([('litres', 'Litres')], 'Odometer Unit', help='Unit of the odometer ',required=True),
'unit_price':fields.float('Unit Price'),
'init_stock':fields.float('Initial Stock'),
'init_stock_taken':fields.date('Initial Stock Taken In'),
}
我假设您使用的是Odoo的版本8或更高版本(因为您的问号),所以首先,如果您要创建一个新模型,比如在本例中,您应该使用新的API,这对您来说会容易得多。因此,让我们将您的代码从旧API移到新API,您要查找的内容将通过
onchange
方法完成:编辑
正如您对我所说的燃料类型没有固定的值一样,该字段不能是
Selection
字段。必须使用Many2one
字段,这意味着您必须首先为燃料类型创建一个类:相关问题 更多 >
编程相关推荐