在选择字段上没有未定义的转换 - Odoo v9社区

时间:2016-08-30 00:56:56

标签: javascript python openerp odoo-9

我在Odoov9社区的模块上有一个选择字段

但是,每次,我点击它,选择一条记录,它会抛出这个错误:

Error: No conversion for undefined

http://localhost:8070/web/static/src/js/framework/pyeval.js:732
Traceback:
wrap@http://localhost:8070/web/static/src/js/framework/pyeval.js:732:29
wrapping_list<.__getitem__@http://localhost:8070/web/static/src/js/framework/pyeval.js:787:16
py.PY_getItem@http://localhost:8070/web/static/lib/py.js/lib/py.js:610:19
py.evaluate@http://localhost:8070/web/static/lib/py.js/lib/py.js:1403:24
py.evaluate@http://localhost:8070/web/static/lib/py.js/lib/py.js:1404:21
py.evaluate@http://localhost:8070/web/static/lib/py.js/lib/py.js:1397:35
py.evaluate@http://localhost:8070/web/static/lib/py.js/lib/py.js:1409:34
py.eval@http://localhost:8070/web/static/lib/py.js/lib/py.js:1453:16
eval_domains/<@http://localhost:8070/web/static/src/js/framework/pyeval.js:862:32
_.forEach@http://localhost:8070/web/static/lib/underscore/underscore.js:145:9
_.mixin/</_.prototype[name]@http://localhost:8070/web/static/lib/underscore/underscore.js:1484:29
eval_domains@http://localhost:8070/web/static/src/js/framework/pyeval.js:853:5
eval_domains/<@http://localhost:8070/web/static/src/js/framework/pyeval.js:867:32
_.forEach@http://localhost:8070/web/static/lib/underscore/underscore.js:145:9
_.mixin/</_.prototype[name]@http://localhost:8070/web/static/lib/underscore/underscore.js:1484:29
eval_domains@http://localhost:8070/web/static/src/js/framework/pyeval.js:853:5
eval_domains/<@http://localhost:8070/web/static/src/js/framework/pyeval.js:867:32
_.forEach@http://localhost:8070/web/static/lib/underscore/underscore.js:145:9
_.mixin/</_.prototype[name]@http://localhost:8070/web/static/lib/underscore/underscore.js:1484:29
eval_domains@http://localhost:8070/web/static/src/js/framework/pyeval.js:853:5
pyeval@http://localhost:8070/web/static/src/js/framework/pyeval.js:946:16
eval_arg@http://localhost:8070/web/static/src/js/framework/pyeval.js:957:16
ensure_evaluated@http://localhost:8070/web/static/src/js/framework/pyeval.js:980:21
.call@http://localhost:8070/web/static/src/js/framework/data_model.js:56:9
DataSet<.name_search@http://localhost:8070/web/static/src/js/framework/data.js:537:16
CompletionFieldMixin.get_search_result@http://localhost:8070/web/static/src/js/views/form_common.js:192:33
FieldMany2One<.render_editable/<.source@http://localhost:8070/web/static/src/js/views/form_relational_widgets.js:271:17
._search@http://localhost:8070/web/static/lib/jquery.ui/jquery-ui.js:7404:3
$.widget/</proxiedPrototype[prop]</<@http://localhost:8070/web/static/lib/jquery.ui/jquery-ui.js:415:19
.search@http://localhost:8070/web/static/lib/jquery.ui/jquery-ui.js:7396:10
$.widget/</proxiedPrototype[prop]</<@http://localhost:8070/web/static/lib/jquery.ui/jquery-ui.js:415:19
$.widget.bridge/$.fn[name]/<@http://localhost:8070/web/static/lib/jquery.ui/jquery-ui.js:513:19
.each@http://localhost:8070/web/static/lib/jquery/jquery.js:383:49
jQuery.prototype.each@http://localhost:8070/web/static/lib/jquery/jquery.js:136:24
$.widget.bridge/$.fn[name]@http://localhost:8070/web/static/lib/jquery.ui/jquery-ui.js:499:4
FieldMany2One<.render_editable/<@http://localhost:8070/web/static/src/js/views/form_relational_widgets.js:189:21
jQuery.event.dispatch@http://localhost:8070/web/static/lib/jquery/jquery.js:4640:50
jQuery.event.add/elemData.handle@http://localhost:8070/web/static/lib/jquery/jquery.js:4309:41

我不喜欢Odoo的新javascript库,所以,我不知道从哪里开始寻找这个,这是否曾经发生在任何人之前?

提前致谢!

修改

这是发票型号代码(我从中调用它):

class account_move_line(models.Model):
_inherit = "account.move.line"

document_class_id = new_fields.Many2one(
    'sii.document_class',
    'Document Type',
    related='move_id.document_class_id',
    store=True,
    readonly=True,
)
document_number = new_fields.Char(
    string='Document Number',
    related='move_id.document_number',
    store=True,
    readonly=True,
    )


class account_journal_sii_document_class(models.Model):
    _name = "account.journal.sii_document_class"
    _description = "Journal SII Documents"

    def name_get(self, cr, uid, ids, context=None):
        result = []
    for record in self.browse(cr, uid, ids, context=context):
        result.append((record.id, record.sii_document_class_id.name))
    return result

    _order = 'journal_id desc, sequence, id'

    sii_document_class_id = new_fields.Many2one('sii.document_class',
                                            'Document Type', required=True)
    sequence_id = new_fields.Many2one(
        'ir.sequence', 'Entry Sequence', required=False,
        help="""This field contains the information related to the numbering \
    of the documents entries of this document type.""")
     journal_id = new_fields.Many2one(
        'account.journal', 'Journal', required=True)
    sequence = new_fields.Integer('Sequence',)

发票视图定义:

<xpath expr="//group[last()]" position="inside">
<filter string="Document Type" icon="terp-folder-orange" domain="[]" context="{'group_by':'sii_document_class_id'}"/>
</xpath>

document_type模型本身:

class sii_document_class(models.Model):
_name = 'sii.document_class'
_description = 'SII Document Class'

name = fields.Char(
    'Name', size=120)
doc_code_prefix = fields.Char(
    'Document Code Prefix', help="Prefix for Documents Codes on Invoices \
    and Account Moves. For eg. 'FAC' will build 'FAC 00001' Document Number")
code_template = fields.Char(
    'Code Template for Journal')
sii_code = fields.Integer(
    'SII Code', required=True)
document_letter_id = fields.Many2one(
    'sii.document_letter', 'Document Letter')
report_name = fields.Char(
    'Name on Reports',
    help='Name that will be printed in reports, for example "CREDIT NOTE"')
document_type = fields.Selection(
    [
        ('invoice', 'Invoices'),
        ('invoice_in', 'Purchase Invoices'),
        ('debit_note', 'Debit Notes'),
        ('credit_note', 'Credit Notes'),
        ('other_document', 'Other Documents')
    ],
    string='Document Type',
    help='It defines some behaviours on automatic journal selection and\
    in menus where it is shown.')
active = fields.Boolean(
    'Active', default=True)
dte = fields.Boolean(
    'DTE', required=True)

第二次编辑

这是表单视图中的实际字段,每次我点击选择一个文档时都会给出错误:

  <h6 style="color:red;text-align:center;text-transform:uppercase;font-weight:900">
  <span t-field="o.journal_document_class_id.sii_document_class_id.name"/>
  </h6>

1 个答案:

答案 0 :(得分:1)

  1. 您不能将QWeb用于普通视图定义(公式,树,搜索等)。

  2. 您不能在普通视野字段定义上使用点符号。

  3. 首先,在您的视图所针对的模型上创建一个相关的Char字段。然后在视图中定义一个简单的字段。

    示例(接近上面的代码):

    class my_model(models.Model):
        _name = 'my.model'
    
        journal_document_class_id = fields.Many2one(
            comodel_name="journal.document.class", string="Journal Doc Class")
        # related field
        sii_document_name = fields.Char(
            string="Sii Document Name",
            related="journal_document_class_id.sii_document_class_id.name")
    
    <h6 style="color:red;text-align:center;text-transform:uppercase;font-weight:900">
        <field name="sii_document_name"/>
    </h6>