Skip to Content
Menu
This question has been flagged
2 Replies
15545 Views

I want inherit customer fracture view from accounting model to another custom module!but it doesn't work!!can anybody help me please!this is my code:

from openerp.osv import fields, osv

class dimo_dimo(osv.osv):

_name = 'dimo.dimo'

_inherit = 'account.invoice.line'

dimo_dimo()

_____________________________

<record model="ir.ui.view" id="view_account_invoice_inherit_tree">

<field name="name">account.invoice.tree.inherit</field>

<field name="model">account.invoice</field>

<field name="type">tree</field>

<field name="inherit_id" ref="account.invoice_tree"/>

</record>

_____________________________

this is the error

ParseError: "ERREUR: une valeur NULL viole la contrainte NOT NULL de la colonne \xab arch \xbb

DETAIL: La ligne en \xe9chec contient (1075, 2015-05-29 10:07:59.043, 1, 2015-05-29 10:07:59.043, t, null, null, 636, account.invoice.tree.inherit, null, 16, extension, account.invoice, tree, 1)

" while parsing file:///C:/Workspace/Odoov8/odoo/addons/dimo/views/dimo_view.xml:6, near

<record model="ir.ui.view" id="view_account_invoice_inherit_tree">

<field name="name">account.invoice.tree.inherit</field>

<field name="model">account.invoice</field>

<field name="type">tree</field>

<field name="inherit_id" ref="account.invoice_tree"/>

<!-- <field name="arch" type="xml">

<field name="state" position="after">

<field name="de"/>

</field>

</field> -->

</record>

Avatar
Discard
Best Answer

field with name="arch"  -is mandatory field, you can't omit that from your record in xml (you've commented it out, uncomment it...)

UPDATE:

there is several errors in your code, I turned it into the example that may work somehow. adapt it to your needs.

v8.0 class dimo_dimo:

from openerp import models, fields

class dimo_dimo(models.Model):
_name = 'account.invoice'
_inherit = 'account.invoice'

de = fields.Char('DE Test', size=64)

v7.0 class dimo_dimo:

from openerp.osv import fields, osv

class dimo_dimo(osv.osv):
_name = 'account.invoice'
_inherit = 'account.invoice'
_columns = {
'de': fields.char('DE Test', size=64),
}


dimo_dimo()

_____________________________


<record id="invoice_tree" model="ir.ui.view"> <!-- you can, but it's NOT necessary to change "id" property, I suggest leave as in parent -->
<field name="name">my.module.name.account.invoice.tree</field> <!-- you have to change it, I suggest to prefix it with you module name (dots instead of underscores) -->
<field name="model">account.invoice</field> <!-- better is to avoid to change this -->
<field name="inherit_id" ref="account.invoice_tree" />
<field name="arch" type="xml"> <!--mandatory! -->
<field name="state" position="after">
<field name="de" />
</field>
</field>
</record>



refer to documentation:


for old versions:

https://doc.odoo.com/6.0/developer/2_6_views_events/  

https://doc.odoo.com/6.0/developer/2_6_views_events/views/view_inheritence/  


for new 8.0 version:

https://www.odoo.com/documentation/8.0/reference/views.html  

https://www.odoo.com/documentation/8.0/reference/views.html#inheritance  

https://www.odoo.com/documentation/8.0/reference/orm.html#inheritance-and-extension  


Avatar
Discard
Author Best Answer

thank you for your answer :) but i've already done that and it gives me this error so i uncomment it

File "C:\Workspace\Odoov8\odoo\openerp\tools\convert.py", line 978, in convert_xml_import

relaxng.assert_(doc)

File "lxml.etree.pyx", line 3384, in lxml.etree._Validator.assert_ (src\lxml\lxml.etree.c:166555)

AssertionError: Invalid attribute type for element field, line 11

i'm not trying to add any fields!i just want to inherit the billing view as it is

Update:

think you for ur help but i've tried your solution but it's not working either 

Error: 

'de': fields.char('DE Test', size=64),

AttributeError: 'module' object has no attribute 'char'

Update

I've version 8 of odoo!and yes i know how to add a fields and i've already create myself a billing module!i was working on it until i've found the inherit notion and it sound maybe better to inherit the billing view then to start it from scratch!

Update(Temur):

for server version I could not guess, as your python code completely in v7.0 style. you can compare it to v8 version that I've added in my answer. anyway both should work, actually there is about 3-5 line python code in dimo_dimo definition, what is wrong in this 3 line you can say? Where come from a strange Error you posted above? very interesting case...

Update(takwa)

hey again,

well,i really appreciate your help!the code you give me with version 8 worked for me!but i still not reach my goal!because what i want is a separate custom module that shows the billing view not 'DE Test' added to the actually account module.

so i've tried this :

from openerp import models, fields

class dimo dimo(models.Model):

_name = 'dimo.dimo' # give a name to my custom module

_inherit = 'account.invoice'

de = fields.Char('DE Test', size=64)

and it gives me this error:

ParseError: "ValidateError

Field(s) `arch` failed against a constraint: Invalid view definition

Error details:

Field `de` does not exist

Error context:

View `my.module.name.account.invoice.tree`

[view_id: 1087, xml_id: dimo.invoice_tree, model: account.invoice, parent_id: 636]" while parsing file:///C:/Workspace/Odoov8/odoo/addons/dimo/views/dimo_view.xml:4, near

<record id="invoice_tree" model="ir.ui.view"> <!-- you can, but it's NOT necessary to change "id" property, I suggest leave as in parent -->

<field name="name">my.module.name.account.invoice.tree</field> <!-- you have to change it, I suggest to prefix it with you module name (dots instead of underscores) -->

<field name="model">account.invoice</field> <!-- better is to avoid to change this -->

<field name="inherit_id" ref="account.invoice_tree"/>

<field name="arch" type="xml"> <!--mandatory! -->

<field name="state" position="after">

<field name="de"/> </field> </field> </record>

help please :'( 

UPDATE(Temur)

read this doc: https://www.odoo.com/documentation/8.0/reference/orm.html#inheritance-and-extension 

if you want simple add new fields, it's not necessary to change "_name" of model. you can leave account.account as model name and add or override stuff... that's a common way... but change a name, it's a bit advanced approach, read link that I posted above to understand how it works. but if you're sure you've to change name, then same time as you change "_name" in python, try to change model name in XML as well:

<field name="model">dimo.dimo</field>

but as I commented early, that's not recommended to change name, unless you've good understanding of it's impact. actually it'll create separated table dimo_dimo in database, rather then adding new fields to the existing account_invoice database table. this way dimo_dimo records are going to be independent records. is that your requirement?


Update(takwa)

hey there :) what i want is a menu shows called billing (new module) witch inherit only the belling view from the account moduleI "prototype inheritance ", i will hide the account module so the user can only see the belling view i dont want him to acces to other account action!My idea was first to hide account and create a custom module "belling" from the scratch but when i found out the inherit notion i thought it may be easy that way!brief,i dont want to add new fields just inherit the belling view.you said it's not recommended!is there another method?any suggestion? help me please!this is my code:

class test_test(models.Model):

_name = 'test.test'

_inherit = 'account.invoice'

de = fields.Text(string='Des', required=True)

and the xml :

<record id="invoice_tree" model="ir.ui.view">

<field name="name">module.name.account.invoice.tree</field>

<field name="model">test.test</field>

<field name="inherit_id" ref="account.invoice_tree" />

<field name="arch" type="xml">

<field name="state" position="after">

<field name="de" /> </field> </field> </record>

help please!!!i get this erreur:

ParseError: "ValidateError

Field(s) `arch` failed against a constraint: Invalid view definition

Error details:

Field `de` does not exist

Error context:

View `account.invoice.form.inherit`

[view_id: 1092, xml_id: test.view_account_invoice_inherit_form, model: account.invoice, parent_id: 638]" while parsing file:///C:/Workspace/Odoov8/odoo/addons/test/views/dimo_view.xml:27, near

<record model="ir.ui.view" id="view_account_invoice_inherit_form">

<field name="name">account.invoice.form.inherit</field>

<field name="model">account.invoice</field>

<field name="type">form</field>

<field name="inherit_id" ref="account.invoice_form"/>

<field name="arch" type="xml">

<field name="partner_id" position="after">

<field name="de"/> </field> </field> </record> 


Avatar
Discard

anyway, you can't solve error by removing mandatory field, you should to solve it otherwise. I updated my answer with example for you.

what is your server version, 7.0 - 8.0?

regarding the error it seems that you were unable to add field "de".... just add some "de" field in your dimo_dimo class, can you? there is all v8 documentation for that do you know how to add field to model? start here if your server is v8 or here for v7 my example of your dimo_dimo class were in v7, because your code posted in answer is written in v7 style.

I added v8 version example of dimo_dimo class, just an advise for future questions: it's useful if you include in your question what is your server version, 8.0 or 7.0 or else... bye.