跳至内容
菜单
此问题已终结
1 回复
5639 查看

Hello

  I have a function field that returns a string.  The string is supposed to be a url pointing to a pdf file on the server.  I have the function created and I know that the correct url is getting generated.  The problem is that string is not showing correctly on the view.

The field on the view is using a 'url' widget so that it becomes a hyperlink that can be clicked

The link looks like this right now:  http://[object Object]

I would like it to show something like this:  http://127.0.01/document_folder/some_pdf_file.pdf

Here is my python function:

def _append_inv_url_2_uuid(self, cr, uid, ids, field, args, context=None):
        res = {}
        for rec in self.browse(cr, uid, ids, context):
            # look up the invoice url by the key name instead of the value.
            # this way if the value changes then no changes will have to be made here
            def_url_id = self.pool.get('ir.config_parameter').search(cr, uid, [('key','=','Invoice uuid URL')])[0]
            
            # get the value of the url key
            url_str = self.pool.get('ir.config_parameter').browse(cr, uid, def_url_id).value

            # get the uuid from the sale order
            uuid = "so?id=%s" % self.browse(cr, uid, ids[0]).uuid

            whole_string = "%s%s" % (url_str, uuid)
            
            res.update({rec.id: {'invoice_url': str(whole_string)}})
        return res

 

Here is the field in the form view:   <field name="invoice_url" widget="url" />

形象
丢弃
最佳答案

Because your field is not multi, so you have {'invoice_url': 'URL'} on that field instead the URL. You have to return

res.update({rec.id: str(whole_string)})

形象
丢弃
编写者

Thank you Grover! That fixed my problem

相关帖文 回复 查看 活动
0
3月 15
3716
1
6月 21
3854
1
3月 15
4110
0
3月 15
3712
2
3月 15
4637