odoo ValueError("预期单身:%s"%self)

时间:2016-04-22 14:28:49

标签: python-2.7 openerp odoo-9

当我选择2个报告并推送" print_report"时,我在odoo中出错了按钮:

        2016-04-22 14:04:34,682 2656 ERROR talm openerp.http:     Exception     during JSON request handling.
Traceback (most recent call last):

      File "/opt/odoo/openerp/http.py", line 643, in _handle_exception
        return super(JsonRequest, self)._handle_exception(exception)
      File "/opt/odoo/openerp/http.py", line 680, in dispatch
        result = self._call_function(**self.params)
      File "/opt/odoo/openerp/http.py", line 316, in _call_function
        return checked_call(self.db, *args, **kwargs)
      File "/opt/odoo/openerp/service/model.py", line 118, in wrapper
        return f(dbname, *args, **kwargs)
      File "/opt/odoo/openerp/http.py", line 309, in checked_call
        result = self.endpoint(*a, **kw)
      File "/opt/odoo/openerp/http.py", line 959, in __call__
        return self.method(*args, **kw)
      File "/opt/odoo/openerp/http.py", line 509, in response_wrap
        response = f(*args, **kw)
      File "/opt/odoo/addons/web/controllers/main.py", line 896, in call_button
        action = self._call_kw(model, method, args, {})
      File "/opt/odoo/addons/web/controllers/main.py", line 884, in _call_kw
        return getattr(request.registry.get(model), method)(request.cr, request.uid, *args, **kwargs)
      File "/opt/odoo/openerp/api.py", line 250, in wrapper
        return old_api(self, *args, **kwargs)
      File "/opt/odoo/openerp/api.py", line 381, in old_api
        result = method(recs, *args, **kwargs)
      File "/ksi/addons/talm/wizard/stock_write_off.py", line 20, in print_report
        data['report_ids'] = self.report_ids.id
      File "/opt/odoo/openerp/fields.py", line 1998, in __get__
        return record.ensure_one()._ids[0]
      File "/opt/odoo/openerp/models.py", line 5402, in ensure_one
        raise ValueError("Expected singleton: %s" % self)
    ValueError: Expected singleton: report.stock.config(21, 16)


I have code:

    report_ids = fields.Many2many(comodel_name='report.stock.config', relation='report_stock_write_off_config_rel',              column1='stock_write_off_id', column2='stock_config_id', string='Report', domain=[('test','=','t')])
    date_from = fields.Datetime('Date From', required=True)
    date_to = fields.Datetime('Date To', required=True)
    detailed = fields.Boolean('Detailed Report')

@api.multi
def print_report(self, data):
    data['report_ids'] = self.report_ids.id
    data['date_from'] = self.date_from
    data['date_to'] = self.date_to
    data['detailed'] = self.detailed
    return self.env['report'].get_action(self, 'talm_stock.report_stock_write_off', data=data)

XML

<record id="view_stock_write_off_wizard" model="ir.ui.view">
    <field name="name">Stock Write Off</field>
    <field name="model">stock.write.off</field>
    <field name="arch" type="xml">
        <form string="Stock Write Off">
            <group>
                <field name="report_ids" widget="many2many_tags"/>
                <field name="date_from"/>
                <field name="date_to"/>
                <field name="detailed"/>
            </group>
            <footer>
                <button name="print_report" string="Retrieve write off data" type="object"  class="oe_highlight"/>
                or
                <button string="Cancel" class="oe_link" special="cancel"/>
            </footer>

我该如何解决这个问题?我需要从report.stock.config()获取一个或多个记录。例如report.stock.config(21,16)

1 个答案:

答案 0 :(得分:3)

问题出在stock_write_off。py

 File "/ksi/addons/talm/wizard/stock_write_off.py", line 20, in print_report
 data['report_ids'] = self.report_ids.id

只需使用 self.report_ids.ids 而不是self.report_ids.id

这将是正确的语法:     data ['report_ids'] = self.report_ids.ids