Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

1

Error Context - field does not exist

By
Carlos DuAl
on 5/17/16, 7:23 AM 802 views

I'm trying to modify a module's behaviour using another module, but I keep getting the same error message.

Traceback (most recent call last):
File "/home/carlos/dbTest/codigo/OCB/openerp/http.py", line 537, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/home/carlos/dbTest/codigo/OCB/openerp/http.py", line 574, in dispatch
result = self._call_function(**self.params)
File "/home/carlos/dbTest/codigo/OCB/openerp/http.py", line 310, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/home/carlos/dbTest/codigo/OCB/openerp/service/model.py", line 118, in wrapper
return f(dbname, *args, **kwargs)
File "/home/carlos/dbTest/codigo/OCB/openerp/http.py", line 307, in checked_call
return self.endpoint(*a, **kw)
File "/home/carlos/dbTest/codigo/OCB/openerp/http.py", line 803, in __call__
return self.method(*args, **kw)
File "/home/carlos/dbTest/codigo/OCB/openerp/http.py", line 403, in response_wrap
response = f(*args, **kw)
File "/home/carlos/dbTest/codigo/OCB/addons/web/controllers/main.py", line 944, in call_kw
return self._call_kw(model, method, args, kwargs)
File "/home/carlos/dbTest/codigo/OCB/addons/web/controllers/main.py", line 936, in _call_kw
return getattr(request.registry.get(model), method)(request.cr, request.uid, *args, **kwargs)
File "/home/carlos/dbTest/codigo/OCB/openerp/api.py", line 268, in wrapper
return old_api(self, *args, **kwargs)
File "/home/carlos/dbTest/codigo/OCB/addons/mail/mail_thread.py", line 348, in fields_view_get
res = super(mail_thread, self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar, submenu=submenu)
File "/home/carlos/dbTest/codigo/OCB/openerp/api.py", line 268, in wrapper
return old_api(self, *args, **kwargs)
File "/home/carlos/dbTest/codigo/OCB/openerp/models.py", line 1545, in fields_view_get
xarch, xfields = View.postprocess_and_fields(cr, uid, self._name, etree.fromstring(result['arch']), view_id, context=ctx)
File "/home/carlos/dbTest/codigo/OCB/openerp/api.py", line 268, in wrapper
return old_api(self, *args, **kwargs)
File "/home/carlos/dbTest/codigo/OCB/openerp/addons/base/ir/ir_ui_view.py", line 837, in postprocess_and_fields
self.raise_view_error(cr, user, message, view_id, context)
File "/home/carlos/dbTest/codigo/OCB/openerp/api.py", line 268, in wrapper
return old_api(self, *args, **kwargs)
File "/home/carlos/dbTest/codigo/OCB/openerp/addons/base/ir/ir_ui_view.py", line 360, in raise_view_error
raise AttributeError(message)
AttributeError: Field `code` does not exist
Error context:
View `CRM - Claims Tree`
[view_id: 1015, xml_id: crm_claim.crm_case_claims_tree_view, model: crm.claim, parent_id: n/a]

This is the module I'm trying to modify. This module modifies the behaviour of crm.claim, and it works fine

        from openerp import models, fields, api
class CrmClaim(models.Model):
_name = "crm.claim.code"
_inherit = "crm.claim"
code = fields.Char(
string='Claim Number', required=True, default="/", readonly=True)
_sql_constraints = [
('crm_claim_unique_code', 'UNIQUE (code)',
'The code must be unique!'),
]
@api.model
def create(self, vals):
if vals.get('code', '/') == '/':
vals['code'] = self.env['ir.sequence'].get('crm.claim')
#vals['stage_id'] = '1' #Set stage to "New" automatically
return super(CrmClaim, self).create(vals)

This is the previou's module's XML view

<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<record model="ir.ui.view" id="crm_claim_add_seq_form_view_inh">
<field name="name">crm.claim.add.seq.form.view.inh</field>
<field name="model">crm.claim</field>
<field name="inherit_id" ref="crm_claim.crm_case_claims_form_view" />
<field name="arch" type="xml">
<field name="name" position="before">
<field name="code" />
</field>
</field>
</record>
<record model="ir.ui.view" id="crm_claim_add_seq_tree_view_inh">
<field name="name">crm.claim.add.seq.tree.view.inh</field>
<field name="model">crm.claim</field>
<field name="inherit_id" ref="crm_claim.crm_case_claims_tree_view" />
<field name="arch" type="xml">
<field name="name" position="before">
<field name="code" />
</field>
</field>
</record>
<record model="ir.ui.view" id="view_crm_case_claims_filter_inh_claimseq">
<field name="name">view.crm.case.claims.filter.inh.claimseq</field>
<field name="model">crm.claim</field>
<field name="inherit_id" ref="crm_claim.view_crm_case_claims_filter" />
<field name="arch" type="xml">
<field name="name" position="attributes">
<attribute name="filter_domain">['|', ('name', 'ilike', self), ('code', 'ilike', self)]</attribute>
</field>
</field>
</record>
</data>
</openerp>

This is my module, I'm just trying to force the stage set to 1 (New) after a claim is created.

        from openerp import models, fields, api
class CrmClaim(models.Model):
_name = "crm.claim.code"
_inherit = "crm.claim"
code = fields.Char(
string='Claim Number', required=True, default="/", readonly=True)
_sql_constraints = [
('crm_claim_unique_code', 'UNIQUE (code)',
'The code must be unique!'),
]
@api.model
def create(self, vals):
if vals.get('code', '/') == '/':
vals['code'] = self.env['ir.sequence'].get('crm.claim')
#vals['stage_id'] = '1' #Set stage to "New" automatically
return super(CrmClaim, self).create(vals)

And this is my directory's structure

odoo

    |[...]
|Upgrade (This is mine)
| |crm_claim_create
| |crmClaimCreate.py
|
|crm (This is the one I'm trying to modify)
| |crm_claim_code
| |models
| | |crm_claim.py
| |views
| |crm_claim_view.xml
|OCB (Odoo's base one)
|addons
|crm_claim
|crm_claim.py

Any idea what's happening?

Thank you

if it works, please mark it as correct

Baiju
on 5/19/16, 9:06 AM
1

Baiju

--Baiju--
3154
| 5 4 8
Kochi, India
--Baiju--
ODOO technical and functional

        I like learning new thing, especially technical thing. I am a quick learner, I can learn technical things very fast. I have good logical skill,  I have immense interest in programming.

e-mail id : baijuks@hotmail.com

Baiju
On 5/17/16, 8:29 AM

Hi,

The problem is with your inheritance,  you are using prototype inheritance instead of class inheritance. To extend the existing class you have to use class inheritance.

ie. if you want to extend the existing class you have to use _name attribute with same name as object or you don't have to give _name.

Please make the following change:

class CrmClaim(models.Model): 
    _name = "crm.claim"  
    _inherit = "crm.claim"

or

class CrmClaim(models.Model):  
 
   _inherit = "crm.claim"



Hope this helps.


Thank you! It works now

Carlos DuAl
on 5/19/16, 7:54 AM
1
ayman mohammed adam
On 5/19/16, 7:35 AM

Hi ,

you must use inherits to add new model name

    class CrmClaim(models.Model):        
    _name = "crm.claim.code"
    _inherits = "crm.claim"
or
class new_class_name(models.Model):
     _inherit = "crm.claim"

Thank you!

Carlos DuAl
on 5/19/16, 7:55 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 5/17/16, 7:23 AM
Seen: 802 times
Last updated: 6/19/16, 10:15 AM