【问题标题】:XML-RPC auto creates records, where web interface does notXML-RPC 自动创建记录,其中 Web 界面不
【发布时间】:2013-11-13 23:57:15
【问题描述】:

我有一张如下所示的表格:

class fnx_sr_shipping(osv.Model):
    _name = 'fnx.sr.shipping'
    _description = 'shipping & receiving entries'
    _inherits = {
       'res.partner': 'partner_id',
       }
    _order = 'appointment_date desc, appointment_time asc'

    _columns = {

       .
       .
       .
       'partner_id': fields.many2one(
            'res.partner',
            'Partner',
            required=True,
            ondelete='restrict'),
       .
       .
       .

OpenERP 需要required=True(如果不存在,OE 会添加它)。

当我使用网络界面时,我可以创建新的运输记录并选择现有的合作伙伴;但是,如果我使用 XML-RPC 尝试同样的事情(在运输记录创建调用中提供 partner_ids)OpenERP 尝试使用默认设置在 res.partner 中创建新记录,这当然会失败,因为某些必填字段有没有默认值(例如name)。

这是我正在使用的 XML-RPC 代码:

import openerplib
OE = PropertyDict()          # allows attribute-style access for keys
OE.conn = openerplib.get_connection(
        hostname='xxx',
        database='yyy',
        login='zzz',
        password='...'
OE.res_partner = conn.get_model('res.partner')
.
.
.
values['partner_id'] = 77     # or whatever it actually is ;)
OE.fnx_shipping.create(values)

我已验证传递的ids 是正确的。

这是我的代码中的错误,还是 OpenERP 中的错误?

【问题讨论】:

  • 如果有人好奇,我通过删除_inherits 并使用函数字段来获取我感兴趣的res.partner 字段来解决这个问题。
  • 如果您只需要res.partner 的链接,则无需在模型中使用_inherits
  • _inherits 似乎是在 view xml 文件中获取访问权限的一种简单方法——在我尝试使用 xml-rpc 之前它工作得很好。
  • 所以你想在fnx.sr.shipping 中使用res.partner 的字段,不是吗?

标签: python openerp xml-rpc


【解决方案1】:

在浏览orm.py 时,我发现了这个:

def name_create(self, cr, uid, name, context=None):
    """Creates a new record by calling :meth:`~.create` with only one
       value provided: the name of the new record (``_rec_name`` field).

       The new record will also be initialized with any default values applicable
       to this model, or provided through the context.

       The usual behavior of :meth:`~.create` applies.
       Similarly, this method may raise an exception if the model has multiple
       required fields and some do not have default values.
    """

所以我尝试在context 字典中提供已经存在的partner_id

OE.fnx_shipping.create(values, context={'default_partner_id':partner_id})

我认为整个混乱是 OpenERP 中的一个错误,但至少有一个不可怕的工作循环。

【讨论】:

    猜你喜欢
    • 2014-03-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多