嘿,我有一个表格,所以我想在 odoo 中使用谷歌地图 View ,特别是在 HR 模块中,我将拥有所有员工的地址。所以当我点击特定 View 时,它应该显示一些带有 map 的 View
最佳答案
你必须继承hr.employee
并将 odoo 方法用于 google_map 在 res.partner
中.
喜欢,
class hr_employee(osv.osv):
_inherit = "hr.employee"
_columns = {
'map': fields.function(google_map_img, string='Map', type='text'),
}
def google_map_img(self, cr, uid, ids, name, args, context=None):
employee = self.browse(cr, uid, ids[0], context=context)
if employee.address_id:
map_img_url = self.browse(cr, SUPERUSER_ID, ids[0], context=context).address_id.google_map_img()
return {ids[0]: map_img_url}
return None
这里是一个功能字段,使用合作伙伴地址计算 map 数据并返回 map url。
使用此字段,您可以使用 <img t-att-src="map"/>
在前端轻松渲染 map
但如果您想在后端表单 View 上呈现它,则必须创建一个使用生成的 url 呈现图像的小部件。 (widget="image")
在google_map_img()
方法有额外的参数,如缩放、高度、宽度。根据您的需要进行更改。
这两种方法用于谷歌地图图像和 map 链接。
def google_map_img(...)
pass
def google_map_link(...)
pass
在addons/website/models/website.py
中搜索此方法
如果您使用此方法,请添加 website
模块取决于您在 __openerp__.py
中的模块
关于xml - 如何在 ODOO 中添加 Google map 链接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34415906/