I'm new to programming for OpenERP 7.0, When you import this module to OpenERP gives me an error:ValidateError Error occurred while validating the field(s) arch: Invalid XML for View Architecture!. I`m not locate the error. I would be very grateful if you help me. thanks.
_init_.py
import new_test
_openerp_.py
{ 'name': 'New Test demo', 'version': '1.0', 'author': 'nasr2ldin', 'category': 'Human Resources', 'summary': 'Document registration', 'website': '', 'description': """ This is a New Test demo Module by nasr2ldin """, 'images': [], 'depends': ['base','hr', 'base_calendar'], 'init_xml': [], 'update_xml': ['new_test_view.xml'], 'installable': True, 'application': True, 'auto_install': False, }
new_test.py
import datetime import time from itertools import groupby from operator import itemgetter import math from openerp.osv import fields, osv from openerp.tools.translate import _ def _employee_get(obj, cr, uid, context=None): if context is None: context = {} ids = obj.pool.get('hr.employee').search(cr, uid, [('user_id', '=', uid)], context=context) if ids: return ids[0] return False class new_test(osv.osv): _name = "new_test.register" _description = "New Test Demo" _columns = { 'new_test_name': fields.char('User Name',size=256), 'new_test_desc': fields.selection([('18-20','18-20'),('20-30','20-30')],'User Age.'), 'new_test_about': fields.char('About'), 'new_test_date': fields.date('Date') } new_test()
new_test_view.xml
<?xml version="1.0" encoding="utf-8"?> <openerp> <data> <record id="new_test_form" model="ir.ui.view"> <field name="name">new_test.line.form</field> <field name="model">new_test.register.</field> <field name="type">form</field> <field name="arch" type="xml"> <form string="New Test" version="7.0"> <field name="sequence" invisible="1"/> <field name="new_test_employee"/> <field name="new_test_name"/> <field name="new_test_desc"/> <field name="new_test_about"/> <field name="new_test_date"/> </form> </field> </record> <record id="new_test_tree" model="ir.ui.view"> <field name="name">new_test.tree</field> <field name="model">new_test.register</field> <!-- <field name="type">tree</field> --> <field name="arch" type="xml"> <tree string="New_test" colors="blue:state=='draft'"> <field name="employee_id"/> <field name="department_id" invisible="1"/> <field name="user_id" invisible="1"/> <field name="new_test_name"/> <field name="new_test_desc"/> <field name="new_test_about"/> <field name="new_test_date"/> </tree> </field> </record> <record model="ir.actions.act_window" id="action_penalty"> <field name="name">new_test</field> <field name="res_model">new_test.register</field> <field name="view_type">form</field> <field name="view_mode">tree,form</field> </record> <menuitem id="new_test_register" name="New Test Register" parent="hr.menu_hr_root" sequence="25"/> <menuitem id="new_test_register_main" name="New Test register" parent="new_test_register" action="action_new_test" sequence="20"/> </data> </openerp>
3 Answers
Answers 1
The problems:
Your form and tree views have fields in them which are not on your model. As in Quentin's answer, add those fields to your model. If your model contains the employee id and you want to display your employee's department on the tree view (for example), add a related field to your model and put that on the view.
You are colouring your tree on state. This is fine but you need to add a state field to your model and it must be in the tree view although it can be invisible (e.g.
<field name="status" invisible="1"/>
).In your
new_test_form
record, in themodel
field, you havenew_test.register.
; remove the trailing.
.
Some helpful hints:
Use of
update_xml
in the__openerp.py__
file is deprecated in 7, usedata
instead.your model should inherit
osv.Model
(orosv.TransientModel
). The old osv and memory are deprecated.column
new_test_about
is a char so should have a size. There may be a default but I can't remember and if there is it will be big so you should put one in.From OpenERP 6.1+ you no longer need to instantiate your models so you can drop the
new_test()
line.As a general style rule, it isn't a good idea to mix ORM classes and module level as you will have inconsistent code. Move
_employee_get
inside the class and access it asself.pool.get('new_test.register')._employee_get
In 7 the
<field name="type"...
in your views is deprecated.
Answers 2
You should define these fields in "_columns" of "new_test" class:
- sequence
- new_test_employee
- employee_id
- department_id
- user_id
And then, update this module.
Answers 3
you have wrongly used object model defined in form view.<field name="model">new_test.register.</field>
This is Wrong , it should be <field name="model">new_test.register</field>
Another mistake you have done is you have used fields which are not defined in the new_test.register class, so You have to add all those fields in _coulmns and then use it in view.
As you are new to OpenERP, Make sure that After improving these things, restart the server to update python changes(i.e. to register new fields to respective tables) and update the module to apply xml changes of view.
sequence, new_test_employee, employee_id, department_id are fields defined in form view and tree view, does not exist in object. so add in object.
and you have wrongly written the method also. Check this link for more information.
Hope this will help you.
0 comments:
Post a Comment