跳至內容
選單
此問題已被標幟
4 回覆
5766 瀏覽次數

Hello everyone,

I'm trying to create a custom module that can add fields to an existing view. I followed this tutorial to create the module : http://www.pixelite.co.nz/article/adding-additional-fields-using-custom-module-openerp-7/ but i get an error when i try to install it : arch: Invalid XML for View Architecture!

I'm using OpenERP 7 on Windows 7.

This is my module configuration:

  • __init__.py

import demo
  • __openerp__.py

{
"name": "Demo module",
"version": "0.2",
"author": "Amre",
"category": "Demo",
"depends": ["base"],
"demo": [],
"data": ["demo_view.xml"],
"installable": True,
}
  • demo.py

from openerp.osv import osv, fields


class demo(osv.osv):
_inherit = "res.partner"

_columns = {
'demo_id': fields.integer('Demo ID', size=11),
}

_defaults = {
'demo_id': 0
}


demo()
  • demo_view.xml

<?xml version="1.0"?>
<openerp>
<data>
<record model="ir.ui.view" id="demo_view_form">
<field name="name">res.partner.form</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="arch" type="xml">
<xpath expr="/form/sheet/group/group/field[@name='website']" position="after">
<field name="demo_id"/>
</xpath>
</field>
</record>
</data>
</openerp>

This module example needs to add a field called "demo_id" to the existing view "base.view_partner_form".


Thanks a lot for you effort and your help.


EDIT 1 : I corrected the xpath with "form", but i still get the same error.

EDIT 2 : made corrections suggested by Akhil P Sivan, i still get the same error again :(

EDIT 3 : made corrections suggested by Temur,the code now works like a charm :D. Good job guys !

頭像
捨棄
最佳答案

You can use partial path:

<xpath expr="//group/group/field[@name='website']" position="after">
<field name="demo_id"/>
</xpath>

UPDATE:

added missing apostrophe to the above code. it should work now.

頭像
捨棄
作者

Thanks for the feedback, i tried your code but i still get the same error :s

Sorry, there were missing ' after website in xpath.. (perhaps I copied it from the question). I updated answer, try now please

作者

GREAT !! it works.. thanks a lot buddy you really helped me.

You're welcome

最佳答案

Remove duplicate occurrence of "data" in your __openerp__.py file. Also _columns and _defaults are different dictionaries. Put the closing brace of _columns before _defaults.  

Keep .py file like this:

from openerp.osv import osv, fields


class demo(osv.osv):
 
_inherit = "res.partner"

_columns = {
'demo_id': fields.integer('Demo ID', size=11),
              }

_defaults = {
'demo_id': 0
}


demo()

Because you wrongly typed form in your xpath expression:

<xpath expr="/form/sheet/group/group/field[@name='website']" position="after">
<field name="demo_id"/>
</xpath>
頭像
捨棄
作者

Thanks for the tip, but still getting the same error.

作者

Thanks a lot for your help, and sorry for those mistakes i'm new to module developement. Unfortunatly i made all the corrections but i still have the same error !!

作者 最佳答案

Thanks for your feedback,

i tried both solutions but i still get the same error when i try to install the module. :\


UPDATE : It works now !! the xpath expression was missing an apostrophe. Thanks a lots to Temur and to Akhil P Sivan for your effort.


頭像
捨棄

Make those corrections in updated answer n try

Did you check after the corrections?

Thanks a lot for your help, and sorry for the mistakes i'm new to module développement.
I made all the corrections but I still get the same error :(

Le 2 nov. 2015 15:53, "Akhil P Sivan" <akhilpsivan01@gmail.com> a écrit :

Did you check after the corrections?

--
Akhil P Sivan
Sent by Odoo S.A. using Odoo access your messages
相關帖文 回覆 瀏覽次數 活動
2
3月 15
8844
2
3月 15
8484
1
3月 15
5940
2
3月 15
5365
1
4月 21
5755