没有关于如何在openerp中创建关系字段的适当示例,如one2many,many2many,many2one和one2one。所以任何人都可以通过销售模块向我展示。
答案 0 :(得分:1)
我没有销售模块的特定示例。但是你可以从下面的语法中得到一般的想法。它对任何类型的应用都有帮助。
::Tag.joins(:posts).distinct.count
基础:openerp.fields._Relational
此类字段的值是大小为0(无记录)或1(单个记录)的记录集。 参数
class openerp.fields.Many2one(comodel_name=None, string=None, **kwargs)
除相关字段或字段扩展名外,属性comodel_name是必需的。
=============================================== ========================
comodel_name -- name of the target model (string)
domain -- an optional domain to set on candidate values on the client side (domain or string)
context -- an optional context to use on the client side when handling that field (dictionary)
ondelete -- what to do when the referred record is deleted; possible values are: 'set null', 'restrict', 'cascade'
auto_join -- whether JOINs are generated upon search through that field (boolean, by default False)
delegate -- set it to True to make fields of the target model accessible from the current model (corresponds to _inherits)
基础:openerp.fields._RelationalMulti
One2many场;这样一个字段的值是comodel_name中所有记录的记录集,这样字段inverse_name等于当前记录。
class openerp.fields.One2many(comodel_name=None, inverse_name=None, string=None, **kwargs)
属性comodel_name和inverse_name是必需的,但相关字段或字段扩展名除外。
=============================================== ===========================
Parameters
comodel_name -- name of the target model (string)
inverse_name -- name of the inverse Many2one field in comodel_name (string)
domain -- an optional domain to set on candidate values on the client side (domain or string)
context -- an optional context to use on the client side when handling that field (dictionary)
auto_join -- whether JOINs are generated upon search through that field (boolean, by default False)
limit -- optional limit to use upon read (integer)
基础:openerp.fields._RelationalMulti
Many2many field;这样一个字段的值是记录集。
参数---------------------------------------------- ------------------
class openerp.fields.Many2many(comodel_name=None, relation=None, column1=None, column2=None, string=None, **kwargs)
除相关字段或字段扩展名外,属性comodel_name是必需的。
参数
comodel_name -- name of the target model (string)
参数
relation -- optional name of the table that stores the relation in the database (string)
column1 -- optional name of the column referring to "these" records in the table relation (string)
column2 -- optional name of the column referring to "those" records in the table relation (string)
The attributes relation, column1 and column2 are optional. If not given, names are automatically generated from model names, provided model_name and comodel_name are different!
答案 1 :(得分:1)
可能会帮助你,
_columns = {
'current_rate': fields.related('company_currency_id','rate_silent', type='float', relation='res.currency',digits_compute=dp.get_precision( 'Account'), string='Current Rate', readonly=True),
}
下面,
company_currency_id =>与新字段相关的同一模型中的字段,
rate_silent =>是您要与新字段关联的字段,表示来自源模型的字段
relation =>是源模型名称,
type =>是源字段的数据类型
注意:在新定义的相关字段中更新值时 将在源字段中更新,但始终是可取的 在新定义的字段中设置只读。