替换看板图像OpenERP

时间:2014-12-20 08:19:27

标签: xml inheritance view openerp

我想从没有图像的公司替换看板图像。 这是我使用的XML。我可以将该图像放在表单视图上但是 到目前为止,它还没有在看板视图上工作。

<field name="name">familae.res.partner.kanban</field>
                <field name="model">res.partner</field>
                <field name="inherit_id" ref="base.res_partner_kanban_view"/>
                <field name="arch" type="xml">           
                    <xpath expr="/kanban/div[@class='oe_kanban_vignette oe_semantic_html_override']" position="replace">
                         <div>
                             <a type="open">
                                <t t-if="record.has_image.raw_value === true">
                                    <img t-att-src="kanban_image('res.partner', 'image_small', record.id.value)" class="oe_kanban_image"/>
                                </t>
                                <t t-if="record.has_image.raw_value === false">
                                    <t t-if="record.is_company.raw_value === true">
                                        <img src="mymodule/static/src/img/myimage.png" class="oe_kanban_image"/>
                                    </t>
                                    <t t-if="record.is_company.raw_value === false">
                                        <img t-att-src="'_s' + '/base/static/src/img/avatar.png'" class="oe_kanban_image"/>
                                    </t>
                                </t>
                            </a>
                        </div>
                    </xpath>
                </field>

日志文件将此作为errormessage:

2014-12-20 08:12:39,369 7031 ERROR openerpfamilae openerp.netsvc: ValidateError
Error occurred while validating the field(s) arch: Invalid XML for View Architecture!
Traceback (most recent call last):
  File "/home/openerp/server/openerp/netsvc.py", line 296, in dispatch_rpc
    result = ExportService.getService(service_name).dispatch(method, params)
  File "/home/openerp/server/openerp/service/web_services.py", line 626, in dispatch
    res = fn(db, uid, *params)
  File "/home/openerp/server/openerp/osv/osv.py", line 190, in execute_kw
    return self.execute(db, uid, obj, method, *args, **kw or {})
  File "/home/openerp/server/openerp/osv/osv.py", line 132, in wrapper
    return f(self, dbname, *args, **kwargs)
  File "/home/openerp/server/openerp/osv/osv.py", line 199, in execute
    res = self.execute_cr(cr, uid, obj, method, *args, **kw)
  File "/home/openerp/server/openerp/osv/osv.py", line 187, in execute_cr
    return getattr(object, method)(cr, uid, *args, **kw)
  File "/home/openerp/server/openerp/addons/base/module/module.py", line 426, in button_immediate_install
    return self._button_immediate_function(cr, uid, ids, self.button_install, context=context)
  File "/home/openerp/server/openerp/addons/base/module/module.py", line 477, in _button_immediate_function
    _, pool = pooler.restart_pool(cr.dbname, update_module=True)
  File "/home/openerp/server/openerp/pooler.py", line 39, in restart_pool
    registry = RegistryManager.new(db_name, force_demo, status, update_module)
  File "/home/openerp/server/openerp/modules/registry.py", line 233, in new
    openerp.modules.load_modules(registry.db, force_demo, status, update_module)
  File "/home/openerp/server/openerp/modules/loading.py", line 354, in load_modules
    loaded_modules, update_module)
  File "/home/openerp/server/openerp/modules/loading.py", line 256, in load_marked_modules
    loaded, processed = load_module_graph(cr, graph, progressdict, report=report, skip_modules=loaded_modules, perform_checks=perform_checks)
  File "/home/openerp/server/openerp/modules/loading.py", line 187, in load_module_graph
    load_update_xml(module_name, idref, mode)
  File "/home/openerp/server/openerp/modules/loading.py", line 74, in <lambda>
    load_update_xml = lambda *args: _load_data(cr, *args, kind='update_xml')
  File "/home/openerp/server/openerp/modules/loading.py", line 124, in _load_data
    tools.convert_xml_import(cr, module_name, fp, idref, mode, noupdate, report)
  File "/home/openerp/server/openerp/tools/convert.py", line 959, in convert_xml_import
    obj.parse(doc.getroot())
  File "/home/openerp/server/openerp/tools/convert.py", line 852, in parse
    self._tags[rec.tag](self.cr, rec, n)
  File "/home/openerp/server/openerp/tools/convert.py", line 819, in _tag_record
    id = self.pool.get('ir.model.data')._update(cr, self.uid, rec_model, self.module, res, rec_id or False, not self.isnoupdate(data_node), noupdate=self.isnoupdate(data_node), mode=self.mode, context=rec_context )
  File "/home/openerp/server/openerp/addons/base/ir/ir_model.py", line 971, in _update
    res_id = model_obj.create(cr, uid, values, context=context)
  File "/home/openerp/server/openerp/addons/base/ir/ir_ui_view.py", line 103, in create
    return super(view, self).create(cr, uid, values, context)
  File "/home/openerp/server/openerp/osv/orm.py", line 4551, in create
    self._validate(cr, user, [id_new], context)
  File "/home/openerp/server/openerp/osv/orm.py", line 1562, in _validate
    raise except_orm('ValidateError', '\n'.join(error_msgs))
except_osv: ('ValidateError', u'Error occurred while validating the field(s) arch: Invalid XML for View Architecture!')

就我个人而言,我无法获得任何信息,但我希望它能帮助你们中的一些人定义问题。

问题在于xpath表达式

2 个答案:

答案 0 :(得分:2)

解决方案1: 覆盖看板视图

    <!-- Partner Kanban View -->
    <record model="ir.ui.view" id="base.res_partner_kanban_view">
        <field name="name">res.partner.kanban</field>
        <field name="model">res.partner</field>
        <field name="arch" type="xml">
            <kanban>
                <field name="color"/>
                <field name="name"/>
                <field name="title"/>
                <field name="email"/>
                <field name="parent_id"/>
                <field name="is_company"/>
                <field name="function"/>
                <field name="phone"/>
                <field name="street"/>
                <field name="street2"/>
                <field name="zip"/>
                <field name="city"/>
                <field name="country_id"/>
                <field name="mobile"/>
                <field name="state_id"/>
                <field name="category_id"/>
                <field name="has_image"/>
                <templates>
                    <t t-name="kanban-box">
                        <div class="oe_kanban_vignette oe_semantic_html_override">
                            <a type="open">
                                <t t-if="record.has_image.raw_value === true">
                                    <img t-att-src="kanban_image('res.partner', 'image_small', record.id.value)" class="oe_kanban_image"/>
                                </t>
                                <t t-if="record.has_image.raw_value === false">
                                    <t t-if="record.is_company.raw_value === true">
                                        <img t-att-src="mymodule/static/src/img/myimage.png" class="oe_kanban_image"/>
                                    </t>
                                    <t t-if="record.is_company.raw_value === false">
                                        <img t-att-src='_s + "/base/static/src/img/avatar.png"' class="oe_kanban_image"/>
                                    </t>
                                </t>
                            </a>
                            <div class="oe_kanban_details">
                                <h4 class="oe_partner_heading"><a type="open"><field name="name"/></a></h4>
                                <div class="oe_kanban_partner_categories"/>
                                <div class="oe_kanban_partner_links"/>
                                <ul>
                                    <li t-if="record.parent_id.raw_value and !record.function.raw_value"><field name="parent_id"/></li>
                                    <li t-if="!record.parent_id.raw_value and record.function.raw_value"><field name="function"/></li>
                                    <li t-if="record.parent_id.raw_value and record.function.raw_value"><field name="function"/> at <field name="parent_id"/></li>
                                    <li t-if="record.city.raw_value and !record.country.raw_value"><field name="city"/></li>
                                    <li t-if="!record.city.raw_value and record.country.raw_value"><field name="country"/></li>
                                    <li t-if="record.city.raw_value and record.country.raw_value"><field name="city"/>, <field name="country"/></li>
                                    <li t-if="record.email.raw_value"><a t-attf-href="mailto:#{record.email.raw_value}"><field name="email"/></a></li>
                                </ul>
                            </div>
                        </div>

                    </t>
                </templates>
            </kanban>
        </field>
    </record>

解决方案2: 继承看板视图并使用xpath替换图像:

    <record model="ir.ui.view" id="familae_base_res_partner_kanban_view">
        <field name="name">familae.res.partner.kanban</field>
        <field name="inherit_id" ref="base.res_partner_kanban_view"/>
        <field name="model">res.partner</field>
        <field name="arch" type="xml">
            <xpath expr='//kanban/templates/t/div/a/t/t[@t-if="record.is_company.raw_value === true"]' position="replace">
                <t t-if="record.is_company.raw_value === true">
                    <img  src="pathtotheimage" class="oe_kanban_image"/>
                </t>
            </xpath>
        </field>
    </record>

答案 1 :(得分:0)

对于odoo 13


        <record model="ir.ui.view" id="view_partner_kanban_view_test">
            <field name="name">res.partner.kanban.testt</field>
            <field name="model">res.partner</field>
            <field name="arch" type="xml">
                <kanban class="o_res_partner_kanban">

                    <field name="state_id"/>
                    <field name="category_id"/>
                    <field name="image"/>
                    <field name="type"/>

                    <templates>
                        <t t-name="kanban-box">
                            <div class="oe_kanban_global_click o_res_partner_kanban">
                                <div class="o_kanban_tags_section oe_kanban_partner_categories"/>

                                <div class="o_kanban_image">


                                   <img t-att-src="kanban_image('res.partner', 'image_128', record.id.raw_value)" t-att-title="record.id.value" t-att-alt="record.id.value" class=""/>


                                    <t t-if="!record.image.raw_value">
                                        <t t-if="record.type.raw_value === 'delivery'">
                                            <img t-att-src='_s + "/base/static/src/img/truck.png"' class="o_kanban_image oe_kanban_avatar_smallbox" alt="avatar"/>
                                        </t>
                                        <t t-if="record.type.raw_value === 'invoice'">
                                            <img t-att-src='_s + "/base/static/src/img/money.png"' class="o_kanban_image oe_kanban_avatar_smallbox" alt="avatar"/>
                                         </t>
                                        <t t-if="record.type.raw_value != 'invoice' &amp;&amp; record.type.raw_value != 'delivery'">
                                            <t t-if="record.is_company.raw_value === true">
                                                <img t-att-src='_s + "/base/static/src/img/company_image.png"' alt="avatar"/>
                                            </t>
                                            <t t-if="record.is_company.raw_value === false">
                                                <img t-att-src='_s + "/base/static/src/img/avatar.png"' alt="avatar"/>
                                            </t>
                                        </t>
                                    </t>
                                </div>
                                <div class="oe_kanban_details">
                                    <table>

                                        <tr t-if="record.mobile.raw_value"><td colspan="2"><field name="mobile"/> - Mobile</td></tr>
                                    </table>
                                </div>
                            </div>

                        </t>
                    </templates>
                </kanban>
            </field>
        </record>