如何在另一个模块中复制一个模块的值[ODOO]

2024-04-26 01:37:02 发布

您现在位置:Python中文网/ 问答频道 /正文

我定制了一个订阅模块

在订阅.py在

from openerp.osv import fields, osv

class subscriptions(osv.osv):
    _name = "subscriptions.sub"
    _description = "subscriptions"

    _columns = {
        'sub_id': fields.integer('Subscription ID', size=10),
        'cust_id': fields.many2one('res.partner','customer_id', 'Customer ID')
     }

在伙伴.py在

^{pr2}$

从客户模块创建订阅时,它也会显示在订阅模块中,但在订阅模块中创建订阅时,它不会显示在客户模块中。在

我能在正确的方向得到帮助吗?在


Tags: 模块columnsnamefrompyimportidfields
1条回答
网友
1楼 · 发布于 2024-04-26 01:37:02

你的问题是如何理解传递给多个11个和1个2个多个字段的参数。在

对很多人来说

documentation中,当前声明如下:

class openerp.fields.Many2one(comodel_name=None, string=None, **kwargs)

The value of such a field is a recordset of size 0 (no record) or 1 (a single record).

Parameters

  • comodel_name name of the target model (string)
  • auto_join whether JOINs are generated upon search through that field (boolean, by default False)

The attribute comodel_name is mandatory except in the case of related fields or field extensions.

因此,fields.Many2one的第二个参数是该字段在接口中的名称。在旧API中,我们可以看到(in openerp/osv/fields.py)第三个参数是auto_join标志:

class many2one(_column):              
    # ...
    def __init__(self, obj, string='unknown', auto_join=False, **args):

因此,在给定的示例中,您应该删除第二个参数,并且在指定manyOne时只有两个参数。在

一个2个月

对于One2many,文档说明:

class openerp.fields.One2many(comodel_name=None, inverse_name=None, string=None, **kwargs)

One2many field; the value of such a field is the recordset of all the records in comodel_name such that the field inverse_name is equal to the current record.

Parameters

  • comodel_name name of the target model (string)
  • inverse_name name of the inverse Many2one field in comodel_name (string)

The attributes comodel_name and inverse_name are mandatory except in the case of related fields or field extensions.

所以在本例中,您是对的,需要第二个参数,但是您选择的(sub_id)是错误的。对于inverse_name,您必须在comodel_name上选择一个Many2one字段,该字段将指向带有One2many的模型。因此在您的实例中,inverse_name应该是cust_id。在

结论

要建立从模型的Many2one字段到另一个模型的One2many字段的关系,One2many字段的inverse_name必须是该字段的技术名称,例如:

^{pr2}$

当您的代码不遵循这一点时,这两个字段之间就不会建立链接,并且您将为每个模型字段设置独立的值。在

相关问题 更多 >