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

How to inherit a button and button action in fleet module?

By
Remya
on 11/11/13, 7:16 AM 5,916 views

I created a custom module to add some details in fleet.vehicle. i want to add image description

I added Accident logs button in my custom module.

xml code:

<openerp>
<data>

<record id="fleet_vehicle_form" model="ir.ui.view">
        <field name="name">fleet.vehicle.form.inherit</field>
        <field name="model">fleet.vehicle</field>
        <field name="inherit_id" ref="fleet.fleet_vehicle_form"/>
        <field name="arch" type="xml">
          <button name='return_action_to_open' position='after'>
             <button name="return_action_open" type="object" string="Accident Logs" help="show the accident logs for this vehicle" /> 
          </button>
            <field name='vin_sn' position='after'>
        <field name="make_year"/>
        <field name="cc"/>
        <field name="engine_no"/>
            </field>
            <field name='car_value' position='after'>
        <field name="registration_no"/>
        <field name="registration_year"/>
        <field name="owner_name"/>
            </field> 
            <field name='color' position='after'>
             <group  col="2">
               <group string="Insurance Details">                     
         <field name="insurance"/>
         <field name="insurance_date"/>
         <field name="insurance_company"/> 
         <field name="insurance_type"/>
               </group>
              </group> 
            </field>
        </field>
    </record>

    <record model='ir.ui.view' id='fleet_vehicle_insurance'>
        <field name="name">fleet.vehicle.insurance.company</field>
        <field name="model">insurance.company</field>
        <field name="arch" type="xml">
          <form string="Insurance Company">
             <group>                     
         <field name="name"/>           
             </group> 
      </form>  
        </field>
    </record>

    <record model='ir.actions.act_window' id='fleet_vehicle_insurance'>
        <field name="name">Insurance Company</field>
        <field name="res_model">insurance.company</field>
        <field name="view_type">form</field>
        <field name="view_mode">tree,form</field>
        <field name="help" type="html">
          <p class="oe_view_nocontent_create">
            Click to create a insurance company
          </p>
        </field>
    </record>

    <record id="fleet_vehicle_extra" model="ir.actions.act_window">
        <field name="name">Vehicles</field>
        <field name="res_model">fleet.vehicle</field>
        <field name="view_type">form</field>
        <field name="view_mode">kanban,tree,form</field>
      <!--  <field name="context">{"default_hr_expense_ok":1}</field>
        <field name="domain">[('hr_expense_ok','=',True)]</field> -->
        <field name="search_view_id" ref="fleet.fleet_vehicle_search"/>
        <field name="help" type="html">
          <p class="oe_view_nocontent_create">
            Click to create a new expense category. 
         </p>
        </field>
    </record>

<record model='ir.ui.view' id='fleet_vehicle_accident_form'>
        <field name="name">fleet.vehicle.accident.form</field>
        <field name="model">fleet.vehicle.accident</field>

        <field name="arch" type="xml">
            <form string="Accident Logs" version="7.0">
                <sheet>
                    <group>
                        <field name="vehicle_id" on_change="on_change_vehicle(vehicle_id)"/>
                        <field name="location" class="oe_inline"/>
                        <field name="type" class="oe_inline"/>
                        <field name="name" />
            <field name="comment" />
                    </group>
                </sheet>
            </form>
        </field>
    </record>

    <record model='ir.ui.view' id='fleet_vehicle_accident_tree'>
        <field name="name">fleet.vehicle.accident.tree</field>
        <field name="model">fleet.vehicle.accident</field>
        <field name="arch" type="xml">
            <tree string="Accident Logs" version="7.0" editable="top">
                <field name="name" />
                <field name="vehicle_id"/>
                <field name="location" />
                <field name="type" />
            </tree>
        </field>
    </record>


<record model='ir.actions.act_window' id='fleet_vehicle_accident_act'>
        <field name="name">Vehicles Accident</field>
    <field name="src_model">fleet.vehicle</field>
        <field name="res_model">fleet.vehicle.accident</field>
        <field name="view_type">form</field>
        <field name="view_mode">tree,form</field>
        <field name="context">{"default_groupby_vehicle" : [active_id]}</field>
        <field name="help" type="html">
          <p class="oe_view_nocontent_create">
            Click to create a new accident log. 
          </p>
          <p>
            Here you can add various accident entries for all vehicles.
            You can also show accident value for a particular vehicle using
            the search field.
          </p>
        </field>
    </record>

<!--<menuitem id="fleet_vehicle_accident_menu" name="Accident Logs" parent="fleet.fleet_vehicles"></menuitem>
    <menuitem action="fleet_vehicle_accident_act" id="fleet_vehicle_accident" parent="fleet_vehicle_accident_menu" string="Result"/>-->

    <menuitem action="fleet_vehicle_accident_act" parent="fleet.fleet_vehicles" id="fleet_vehicle_accident_menu"/>




 </data>

</openerp>

Python code:

from openerp.osv import fields, osv

import time

import datetime

from openerp import tools

from openerp.osv.orm import except_orm

from openerp.tools.translate import _

from dateutil.relativedelta import relativedelta

class fleet_vehicle_accident(osv.Model):

def on_change_vehicle(self, cr, uid, ids, vehicle_id, context=None):
        if not vehicle_id:
           return {}
        vehicle = self.pool.get('fleet.vehicle').browse(cr, uid, vehicle_id, context=context)
        odometer_unit = vehicle.odometer_unit
        driver = vehicle.driver_id.id
        return {
             'value': {
                      'odometer_unit': odometer_unit,
                      'purchaser_id': driver,
             }
        }
_name='fleet.vehicle.accident'
_inherit = "fleet.vehicle"
_description='Accident log for a vehicle'
    _columns = {
    'vehicle_id' : fields.many2one('fleet.vehicle', 'Vehicle'),
    'name' : fields.datetime('Accident Date&Time', help='Accident date'),
    'location' : fields.char('Accident Location', help='Accident Location'),
    'type' : fields.selection([('major', 'Major'),('minor','Minor')], 'Accident Type', help='Select the accident type'),
    'comment' : fields.text('Description'),
}

class fleet_vehicle(osv.osv):

_inherit = "fleet.vehicle"

    _columns = {

            'cc': fields.char('Cylinder Capacity(CC)', size=64, help='Cylinder Capacity of the vehicle'),

    'make_year': fields.date('Make Year', help='Date when the vehicle has been made'),

    'registration_no' : fields.float('Registration No', help='Registration number of the vehicle'),

    'registration_year': fields.date('Registration Year', help='Date when the vehicle has been registrated'),

    'engine_no' : fields.float('Engine No', help='Engine number of the vehicle'),

    'owner_name': fields.many2one('res.company','Owner Name', size=64, help='Name of the owner'),

    'insurance' : fields.char('Insurance No', size=64, help='Insurance Number of the vehicle'),

    'insurance_date' : fields.date('Insurance Date', help='Insurance Date of the vehicle'),

    'insurance_company' : fields.many2one('insurance.company', 'Insurance Company', help='Select the insurance company'),

    'insurance_type' : fields.selection([('thirdparty', 'Third-Party Liability'),('firstparty','First-Party Expense'),('nonpolicy', 'Non-Policy-Owners')], 'Insurance Type', help='Select the insurance type'),


           }   



def return_action_open(self, cr, uid, ids, context=None):
        """ This opens the xml view specified in xml_id for the current vehicle """
        if context is None:
           context = {}
        if context.get('xml_id'):
           res = self.pool.get('ir.actions.act_window').for_xml_id(cr, uid ,'fleet', context['xml_id'], context=context)
           res['context'] = context
           res['context'].update({'default_vehicle_id': ids[0]})
           res['domain'] = [('vehicle_id','=', ids[0])]
           return res
        return False

fleet_vehicle()

class insurance_company(osv.osv):

_name = 'insurance.company'

    _description = 'Information on a vehicle'

    _columns = {

        'name': fields.char('Insurance Company', size=64, help='Add new insurance company name'),

    }

insurance_company()

But it shows error: KeyError: 'fleet_vehicle_accident_act'

OpenERP Server Error
Client Traceback (most recent call last):
  File "/opt/openerp/server/openerp/addons/web/http.py", line 204, in dispatch
    response["result"] = method(self, **self.params)
  File "/opt/openerp/server/openerp/addons/web/controllers/main.py", line 1132, in call_button
    action = self._call_kw(req, model, method, args, {})
  File "/opt/openerp/server/openerp/addons/web/controllers/main.py", line 1120, in _call_kw
    return getattr(req.session.model(model), method)(*args, **kwargs)
  File "/opt/openerp/server/openerp/addons/web/session.py", line 42, in proxy
    result = self.proxy.execute_kw(self.session._db, self.session._uid, self.session._password, self.model, method, args, kw)
  File "/opt/openerp/server/openerp/addons/web/session.py", line 30, in proxy_method
    result = self.session.send(self.service_name, method, *args)
  File "/opt/openerp/server/openerp/addons/web/session.py", line 103, in send
    raise xmlrpclib.Fault(openerp.tools.ustr(e), formatted_info)


Server Traceback (most recent call last):
  File "/opt/openerp/server/openerp/addons/web/session.py", line 89, in send
    return openerp.netsvc.dispatch_rpc(service_name, method, args)
  File "/opt/openerp/server/openerp/netsvc.py", line 292, in dispatch_rpc
    result = ExportService.getService(service_name).dispatch(method, params)
  File "/opt/openerp/server/openerp/service/web_services.py", line 626, in dispatch
    res = fn(db, uid, *params)
  File "/opt/openerp/server/openerp/osv/osv.py", line 188, in execute_kw
    return self.execute(db, uid, obj, method, *args, **kw or {})
  File "/opt/openerp/server/openerp/osv/osv.py", line 131, in wrapper
    return f(self, dbname, *args, **kwargs)
  File "/opt/openerp/server/openerp/osv/osv.py", line 197, in execute
    res = self.execute_cr(cr, uid, obj, method, *args, **kw)
  File "/opt/openerp/server/openerp/osv/osv.py", line 185, in execute_cr
    return getattr(object, method)(cr, uid, *args, **kw)
  File "/opt/openerp/server/openerp/addons/base/module/module.py", line 424, in button_immediate_install
    return self._button_immediate_function(cr, uid, ids, self.button_install, context=context)
  File "/opt/openerp/server/openerp/addons/base/module/module.py", line 475, in _button_immediate_function
    _, pool = pooler.restart_pool(cr.dbname, update_module=True)
  File "/opt/openerp/server/openerp/pooler.py", line 39, in restart_pool
    registry = RegistryManager.new(db_name, force_demo, status, update_module)
  File "/opt/openerp/server/openerp/modules/registry.py", line 218, in new
    openerp.modules.load_modules(registry.db, force_demo, status, update_module)
  File "/opt/openerp/server/openerp/modules/loading.py", line 345, in load_modules
    processed = load_marked_modules(cr, graph, states_to_load, force, status, report, loaded_modules, update_module)
  File "/opt/openerp/server/openerp/modules/loading.py", line 256, in load_marked_modules
    loaded, processed = load_module_graph(cr, graph, progressdict, report=report, skip_modules=loaded_modules, perform_checks=perform_checks)
  File "/opt/openerp/server/openerp/modules/loading.py", line 188, in load_module_graph
    load_data(module_name, idref, mode)
  File "/opt/openerp/server/openerp/modules/loading.py", line 76, in <lambda>
    load_data = lambda *args: _load_data(cr, *args, kind='data')
  File "/opt/openerp/server/openerp/modules/loading.py", line 124, in _load_data
    tools.convert_xml_import(cr, module_name, fp, idref, mode, noupdate, report)
  File "/opt/openerp/server/openerp/tools/convert.py", line 954, in convert_xml_import
    obj.parse(doc.getroot())
  File "/opt/openerp/server/openerp/tools/convert.py", line 847, in parse
    self._tags[rec.tag](self.cr, rec, n)
  File "/opt/openerp/server/openerp/tools/convert.py", line 807, in _tag_record
    f_val = _eval_xml(self,field, self.pool, cr, self.uid, self.idref)
  File "/opt/openerp/server/openerp/tools/convert.py", line 154, in _eval_xml
    for n in node]), idref)
  File "/opt/openerp/server/openerp/tools/convert.py", line 149, in _process
    return s % idref
KeyError: 'fleet_vehicle_accident_act'

How can i solve this?

Can you post your xml file here ?

Tuxservices, Jeudy Nicolas
on 11/11/13, 6:07 PM

this error cleared, but i have another error.

Remya
on 11/11/13, 11:58 PM

Can you copy the full error message ? becaus I have no info to help you :) I think res = self.pool.get('ir.actions.act_window').for_xml_id(cr, uid ,'fleet', context['xml_id'], context=context) is wrong. What is the name of your custom module ?

Tuxservices, Jeudy Nicolas
on 11/12/13, 12:31 PM

name of the custom module is vehicle. i think your guess is right.

Remya
on 11/12/13, 1:35 PM

I have updated my question. Please check it

Remya
on 11/13/13, 12:57 AM
0

Jeudy Nicolas

--Jeudy Nicolas--
1181
| 6 7 8
PELOUSEY, France
--Jeudy Nicolas--

- Linux administrator - Functional guy with OpenERP - Python, html, css, javascript developer OpenERP Ready Partner

Jeudy Nicolas
On 11/11/13, 6:07 PM

Hello,

In your custom module you have to set depends value to ['base','fleet'] in you __openerp__.py file ?

In my version of fleet addons I have no fleet_vehicle_accident_act menu xmlid. I think you have not correctly create the new menu.

Update:

Change this function and replace fleet by your custom module name as shown.

res = self.pool.get('ir.actions.act_window').for_xml_id(cr, uid ,'vehicle', context['xml_id'], context=context)

File "/opt/openerp/server/openerp/addons/base/ir/ir_model.py", line 861, in _get_id raise ValueError('No such external ID currently defined in the system: %s.%s' % (module, xml_id)) ValueError: No such external ID currently defined in the system: vehicle.fleet_vehicle_odometer_act

Remya
on 11/13/13, 4:16 AM

Again error. I cant access remaining button. Now error cleared in Accident logs button

Remya
on 11/13/13, 4:16 AM

Ok,

  • Can you say if your button "acciden logs" is working ?
  • Can you say when did you have this new error. for me fleet_vehicle_odometer_act is part of fleet module and not vehicle module. and I find no reference for fleet_vehicle_odometer_act on you posted code. Can I download your code to check in my local install ?
Tuxservices, Jeudy Nicolas
on 11/13/13, 4:19 PM

O sure. You can download it. Now my accident log button is working. it is in my custom module vehicle. i inherit some fields in fleet module using my custom module vehicle. after installing my custom module. then click on the odometer button, i got the new error .

Remya
on 11/14/13, 12:24 AM

have you a link or a tar file to download ?

Tuxservices, Jeudy Nicolas
on 11/14/13, 4:21 AM

I will upload it.

Remya
on 11/14/13, 4:34 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

0 follower(s)

Stats

Asked: 11/11/13, 7:16 AM
Seen: 5916 times
Last updated: 3/16/15, 8:10 AM