如何在odoo 9中通过模块更改默认徽标

时间:2016-07-25 13:48:48

标签: xml python-2.7 odoo-9

我在安装服装模块时尝试更改odoo的徽标。意味着我将提供的任何徽标将取代默认徽标。所以我试图覆盖,控制器正在执行,但结果没有显示。不会产生任何错误。下面的代码是我的控制器代码。

main.py

class Extension(main.Binary):

@http.route([
    '/demo_theme/extension/company_logo',
    '/logo',
    '/logo.png',
], type='http', auth="none", cors="*")
def company_logo(self, dbname=None, **kw):
    imgname = 'logo'
    imgext = '.png'
    placeholder = functools.partial(get_resource_path, 'demo_theme', 'static', 'src', 'img')
    uid = None
    if request.session.db:
        dbname = request.session.db
        uid = request.session.uid
    elif dbname is None:
        dbname = db_monodb()

    if not uid:
        uid = openerp.SUPERUSER_ID

    if not dbname:
        response = http.send_file(placeholder(imgname + imgext))
    else:
        try:
            # create an empty registry
            registry = openerp.modules.registry.Registry(dbname)
            with registry.cursor() as cr:
                cr.execute("""SELECT c.logo_web, c.write_date
                                FROM res_users u
                           LEFT JOIN res_company c
                                  ON c.id = u.company_id
                               WHERE u.id = %s
                           """, (uid,))
                row = cr.fetchone()
                if row and row[0]:
                    image_base64 = str(row[0]).decode('base64')
                    image_data = StringIO(image_base64)
                    imgext = '.' + (imghdr.what(None, h=image_base64) or 'png')
                    response = http.send_file(image_data, filename=imgname + imgext, mtime=row[1])
                else:
                    response = http.send_file(placeholder('nologo.png'))
        except Exception:
            response = http.send_file(placeholder(imgname + imgext))

    return response

我在我的.xml文件中调用此控制器

<img src='/demo_theme/extension/company_logo'/>

但是,图像没有被替换。所以任何人都有任何想法请与我分享。

由于

2 个答案:

答案 0 :(得分:1)

是的,我得到了答案,你应该覆盖weblient.js中的update_logo()方法

.js文件

var WebClient = require('web.WebClient');

WebClient.include({
 update_logo: function() {
    var company = session.company_id;
    var img = session.url('/demo_theme/extension/company_logo' + '?db=' + session.db + (company ? '&company=' + company : ''));
    this.$('.oe_logo img').attr('src', '').attr('src', img);
    this.$('.oe_logo_edit').toggleClass('oe_logo_edit_admin', session.uid === 1);
  },
}); 

只需更改控制器的路径即可。

答案 1 :(得分:0)

尝试http://127.0.0.1:8069/logo如果显示徽标意味着你的覆盖是正确的,如果不是那意味着你的方法不起作用并使用一些print'message'来看看它是否在调用你的方法而不是原来的

并检查您是否在 init .py文件中导入了py文件