Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Odoo - Internal Server Error on custom module uninstall

I am trying to make a simple inheritance module so I can add more fields in new Opportunity Form but odoo doesn't like my code. I am pretty new in Odoo and Python so don't blame me :(

mymodule.py:

from openerp.osv import fields, osv 

class crm_lead_mymodule(osv.osv):
    _inherit = 'crm.lead'

    _columns = {
        'product_type' : fields.selection( [('basic', 'Basic'),('pro', 'Pro'),], ),
    }

mymodule.xml:

<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
    <record id="view_crm_opportunity_mymodule_form" model="ir.ui.view">
        <field name="name">crm.lead.mymodule.inherit</field>
        <field name="model">crm.lead</field>
        <field name="inherit_id" ref="crm.crm_case_form_view_oppor"/>
        <field name="arch" type="xml">
            <xpath expr="//notebook/page[@name='lead']" position="after">
                <page string="Product Information">
                    <group col="3">
                            <field name="product_type"/>
                    </group>
                </page>
            </xpath>
        </field>
    </record>
</data>
</openerp>

I tried a lot of installs, after changes in my code until I uninstall it and odoo crashed. I am getting "Internal Server error" with the following log:

Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/werkzeug/serving.py", line 177, in run_wsgi
    execute(self.server.app)
  ...
  ...
  ...
  File "/usr/lib/python2.7/dist-packages/openerp/modules/registry.py", line 168, in load
    model = cls._build_model(self, cr)
  File "/usr/lib/python2.7/dist-packages/openerp/models.py", line 593, in _build_model
    original_module = pool[name]._original_module if name in parents else cls._module
  File "/usr/lib/python2.7/dist-packages/openerp/modules/registry.py", line 84, in __getitem__
    return self.models[model_name]
KeyError: 'crm.lead'
like image 600
Alex Bogias Avatar asked Jan 04 '16 16:01

Alex Bogias


1 Answers

First what you need it is check depends section in your openerp.py. This is must be something like that: 'depends': ['base', 'crm'],. After this try to drop your local db and create new from GUI.

About problem in chat(opportunity button in customers)... In Sales -> Customers works form from base module. You can use developer mode to check it. In this form use res.partner object and base.view_partner_form.

How to add your fields to this form? Just create test_view.xml:

<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
    <record id="view_partner_form_mymodule_form" model="ir.ui.view">
        <field name="name">res.partner.mymodule.inherit</field>
        <field name="model">res.partner</field>
        <field name="inherit_id" ref="base.view_partner_form"/>
        <field name="arch" type="xml">
            <xpath expr="//notebook/page" position="after">
                <page string="Product Information">
                    <!-- your fields here  -->
                </page>
            </xpath>
        </field>
    </record>
</data>
</openerp>

And add your view to openerp.py like that:

'data': [
     'test_view.xml',
],

Be careful! In this view use res.partner model, but not crm.lead. Hope this help you!

like image 176
Danila Ganchar Avatar answered Oct 23 '22 03:10

Danila Ganchar