I was trying to follow this guide of building a web-module: https://doc.openerp.com/trunk/web/module/
I created the following files according to guide:
// static/src/js/first_module.js
openerp.web_example = function (instance) {
instance.web.client_actions.add('example.action', 'instance.web_example.action');
instance.web_example.action = function (parent, action) {
console.log("Executed the action", action);
};
};
openerp.py
# __openerp__.py
{
'name': "Web Example",
'description': "Basic example of a (future) web module",
'category': 'Hidden',
'depends': ['web'],
'data': ['web_example.xml'],
'js': ['static/src/js/first_module.js'],
}
web_example.xml
<!-- web_example/web_example.xml -->
<openerp>
<data>
<record model="ir.actions.client" id="action_client_example">
<field name="name">Example Client Action</field>
<field name="tag">example.action</field>
</record>
<menuitem action="action_client_example"
id="menu_client_example"/>
</data>
</openerp>
init.py is empty.
Now the "Example Client Action" link appears to the topbar of the admin-panel like it should but when I click it I get a notification saying "Could not find client action example.action"
I have checked my code few times to ensure it's similar to guide's. Am I just blind to some minor error, is there a misconception or what could be the problem? Should there be something in the init.py file? If yes, then what?
In v8 adding of static files is different as v7.
You must define static files in view, where you inheriting core views.
1. in module folder create folder named views
2. create in where file named: you_module_name.xml
3. in openerp.py add: 'data': ['views/you_module_name.xml']
4. in you_module_name.xml add:
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<template id="assets_backend" name="you_module_name assets" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<link rel="stylesheet" href="/you_module_name/static/src/css/you_module_name.css"/>
<script type="text/javascript" src="/you_module_name/static/src/js/you_module_name.js"></script>
</xpath>
</template>
</data>
if you haven't find any way, then please follow below step for OpenERP8/odoo.
Add below contain in your web_example module.
web_example
└── views
└──document.xml
In document.xml add below contain.
<data>
<template id="web_example_assets_backend" name="web_example assets" inherit_id="web.assets_backend">`enter code here`
<xpath expr="." position="inside">
<script type="text/javascript" src="/web_example/static/src/js/first_module.js"></script>
</xpath>
</template>
</data>
Now,modify openerp.py
openerp.py
{
'name': "Web Example",
'description': "Basic example of a (future) web module",
'category': 'Hidden',
'depends': ['web'],
'data': ['web_example.xml','views/document.xml'],
}
Thats it.
now,your js file is loaded in v8/odoo. :)
same way you can add your css file in document.xml
Thank You.
I am taking my first steps into biulding a web client, and just tried this tutorial yesterday. So I'm not sure my answer is right, but, is the name of your module "web_example"? If not, you should instantiate it with the name of your module in your js file. (it's working for me and got through the tutorial and got the timer working).
Good luck!
Related
I am in the process of learning to develop Odoo and started by following this tutorial https://www.odoo.com/documentation/15.0/developer/howtos/rdtraining/06_firstui.html . Currently I am stuck on chapter 6.
I created a estate_menus.xml file and a estate_property_views.xml file in the views folder. My code looks like that:
estate_property_views.xml
<?xml version="1.0"?>
<odoo>
<record id="estate_property_action" model="ir.actions.act_window">
<field name="name">Properties</field>
<field name="res_model">estate.property</field>
<field name="view_mode">tree,form</field>
<field name="help" type="html">
<p class="o_view_nocontent_smiling_face">
Create a new property
</p>
</field>
</record>
</odoo>
#estate_menus.xml
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<menuitem id="estate_menu_root" name="Real Estate">
<menuitem id="estate_first_level_menu" name="Advertisements">
<menuitem id="estate_menu_action" action="estate_property_action"/>
</menuitem>
</menuitem>
</odoo>
This is my manifest file:
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
{
'name' : 'Estate',
'application': True,
'depends' : ['base'],
'data': [
'security/ir.model.access.csv',
'views/estate_property_views.xml',
'views/estate_menus.xml',
]
}
Everything looks fine except the Create button is missing and I have no idea why. Could you give me hint in which file I made a mistake? Thank you very much!
I tried the code above but the button is still missing.
In Chapter 5, you have created the access rights for your model and as per tutorial
id,name,model_id/id,group_id/id,perm_read,perm_write,perm_create,perm_unlink
access_test_model,access_test_model,model_test_model,base.group_user,1,0,0,0
You have given only read access to base.group_user so you can modify your ir.model.access.csv and you can give write and create and unlink access as below:
id,name,model_id/id,group_id/id,perm_read,perm_write,perm_create,perm_unlink
access_test_model,access_test_model,model_test_model,base.group_user,1,1,1,1
I have had the same problem. For the moment, I solved it by unifying both files.
Also try creating the estate_menus.xml file with nothing inside, just:
<odoo></odoo>
and i have the same problem.
I'm still looking for the correct answer. Greetings
Is there any way to can make optional dependencies in Odoo 14 CE?
I know that there is a dependency attribute in the manifest file that we need to specify, and yes, I have been using it to the best of my abilities.
However, I sometimes need to write some code for only when a module is installed, but even if it isn't then the rest code should function properly without such module.
For example, My custom module will add a field in sale and account, but if this database has purchase installed then it will also add a field in it too. Pretty simple concept, right, but I can't find a way to do it in a single module.
You can use post_init_hook, which is executed right after the module’s installation, to check if the purchase (purchase.order is in registry) module is installed and add the custom field. You can even load an XML file to add the custom field by inheritance using the convert_xml_import function which convert and import XML files.
It is similar to adding the field manually to the corresponding model and view.
When you uninstall the module, the custom field will not be deleted and to do so, you will need to use the uninstall_hook, you will also need to delete the view manually because of the following user error:
User Error
Cannot rename/delete fields that are still present in views
Fields: purchase.order.x_reference
View: purchase.order.form
First set the post_init_hook, uninstall_hook functions inside the __manifest__.py file:
'post_init_hook': '_module_post_init',
'uninstall_hook': '_module_uninstall_hook',
Then define those functions inside the __init__.py file:
import os
from odoo import fields, api, SUPERUSER_ID, tools, modules
from odoo.tools.misc import file_open
def _module_uninstall_hook(cr, registry):
if 'purchase.order' in registry:
env = api.Environment(cr, SUPERUSER_ID, {})
env.ref('stackoverflow_14.purchase_order_form').unlink()
env['ir.model.fields'].search([('name', '=', 'x_reference')]).unlink()
def _module_post_init(cr, registry):
if 'purchase.order' in registry:
env = api.Environment(cr, SUPERUSER_ID, {})
mp = env['ir.model'].search([('model', '=', 'purchase.order')], limit=1)
mp.write({'field_id': [(0, 0, {
'name': 'x_reference',
'field_description': "Reference",
'ttype': 'char',
})]})
pathname = os.path.join(modules.get_module_path('stackoverflow_14'), 'views', 'purchase_order.xml')
with file_open(pathname, 'rb') as fp:
tools.convert.convert_xml_import(cr, 'stackoverflow_14', fp)
The purchase_order.xml file defined inside views use the view inheritance to add the custom field to the purchase_order_form form view:
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<data>
<record id="purchase_order_form" model="ir.ui.view">
<field name="name">purchase.order.form</field>
<field name="model">purchase.order</field>
<field name="inherit_id" ref="purchase.purchase_order_form"/>
<field name="arch" type="xml">
<field name="partner_ref" position="after">
<field name="x_reference"/>
</field>
</field>
</record>
</data>
</odoo>
I setup and installed Odoo. After installation I did scaffolding to create a test module. Within that module I added some code and the module appeared under my module list. However after installation I do not see the module on my app list. Below is my code:
button_action_demo.py
from odoo import models, fields, api
#Non-odoo library
import random
from random import randint
import string
class button_action_demo(models.Model):
_name = 'button.demo'
name = fields.Char(required=True,default='Click on generate name!')
password = fields.Char()
def generate_record_name(self):
self.ensure_one()
#Generates a random name between 9 and 15 characters long and writes it to the record.
self.write({'name': ''.join(random.SystemRandom().choice(string.ascii_uppercase + string.digits) for _ in range(randint(9,15)))})
def generate_record_password(self):
self.ensure_one()
#Generates a random password between 12 and 15 characters long and writes it to the record.
self.write({
'password': ''.join(random.SystemRandom().choice(string.ascii_uppercase + string.digits) for _ in range(randint(12,15)))
})
def clear_record_data(self):
self.ensure_one()
self.write({
'name': '',
'password': ''
})
views.xml
<record model="ir.ui.view" id="view_buttons_form">
<field name="name">Buttons</field>
<field name="model">button.demo</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Button record">
<!--The header tag is built to add buttons within. This puts them at the top -->
<header>
<!--The oe_highlight class gives the button a red color when it is saved.
It is usually used to indicate the expected behaviour. -->
<button string="Generate name" type="object" name="generate_record_name" class="oe_highlight"/>
<button string="Generate password" type="object" name="generate_record_password"/>
<button string="Clear data" type="object" name="clear_record_data"/>
</header>
<group>
<field name="name"/>
<field name="password"/>
</group>
</form>
</field>
</record>
<!--The action -->
<record model="ir.actions.act_window" id="buttons_example_action">
<field name="name">Create new record</field>
<field name="res_model">button.demo</field>
<field name="view_mode">form,tree</field>
<field name='view_id' ref='view_buttons_form'/>
</record>
<!-- top level menu: no parent -->
<menuitem id="main_button_menu" name="Buttons demo"/>
<menuitem id="button_menu" name="Buttons demo"
parent="main_button_menu"/>
<menuitem id="menu_detail_logging"
action="buttons_example_action" parent="button_menu"
sequence="20"/>
</data>
</odoo>
manifest.py
{
'name': "button_action_demo",
'summary': """
Short (1 phrase/line) summary of the module's purpose, used as
subtitle on modules listing or apps.openerp.com""",
'description': """
Long description of module's purpose
""",
'author': "My Company",
'website': "http://www.yourcompany.com",
# Categories can be used to filter modules in modules listing
# Check https://github.com/odoo/odoo/blob/13.0/odoo/addons/base/data/ir_module_category_data.xml
# for the full list
'category': 'Uncategorized',
'version': '0.1',
# any module necessary for this one to work correctly
'depends': ['base'],
# always loaded
'data': [
# 'security/ir.model.access.csv',
'views/views.xml',
'views/templates.xml',
],
# only loaded in demonstration mode
'demo': [
'demo/demo.xml',
],
}
security.py
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_button_action_demo_button_action_demo,button_action_demo.button_action_demo,model_button_action_demo_button_action_demo,base.group_user,1,1,1,1
Can someone please guide me what am I missing on my code. I'm more than happy to share more code if required but I think I have provided most of the bits
Add security or open debug mood and then click become super user in odoo 13 admin is not super user but you can make him by doing above
If module is not visible in app list then check few things, listed below.
Restart your Server.
Update App list.
Place module in right addons PATH.
If your security file is not working well or something wrong with your manifest file all these things will happen during installation or after installation.
I need to change the "Powered" in "Powered by Odoo" footer to "Made",
So the footer of my Odoo (Formerly OpenERP) Version 8.0-aab3d9f will be "Made by Odoo"
any ideas??
Instead of changing directly in the core of odoo (which is not appreciated), you can create a new module that depends on web module.
Then you can extend template web.menu_secondary from webclient_templates.xml in web module, like this:
-> _ _openerp__.py file:
{
'name': "My Module",
# for the full list
'category': 'Web',
# any module necessary for this one to work correctly
'depends': ['web'],
# always loaded
'data': ['templates.xml'],
'demo': [],
}
-> templates.xml file:
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<template id="menu_secondary" inherit_id="web.menu_secondary">
<div class="oe_footer" position="replace">
<div class="oe_footer">
Made by <span>Odoo</span>
</div>
</div>
</template>
</data>
</openerp>
First go to your Odoo web module and open below file.
addons => web => views => webclient_templates.xml
Now find this tag <div class="oe_footer"> and edit it like
<div class="oe_footer">
Made by <span>Odoo</span>
</div>
Save it and refresh your browser. Hope you get what you want.
You can use the HTML Editor of the Website module to change your site's copyright footer:
Customize > HTML Editor
Website HTML Editor Footer Copyright
As this is a fast and clean way to accomplish what you're asking for, though changes will be saved directly to working database. If you want to replicate your changes in different databases, the best approach is to make a custom module.
I installed Odoo v8 on my poste windows 7.
I created a new module "openacademy" , by following the tutorial "Building a Module" on the official website:
https://www.odoo.com/documentation/8.0/howtos/backend.html
then I zip my file "openacademy" ==> "openacademy.zip".
The problem: When I try to import the module, I get this error:
Import Module
WARNING odoo openerp.models: Cannot execute name_search, no _rec_name defined on base.import.module
INFO odoo werkzeug: 127.0.0.1 - - [16/Dec/2014 17:53:03] "POST /web/dataset/call_kw/base.import.module/search_read HTTP/1.1" 200 -
WARNING odoo openerp.modules.module: module openacademy: module not found
INFO odoo openerp.addons.base_import_module.models.ir_module: module openacademy: loading templates.xml
INFO odoo openerp.addons.base_import_module.models.ir_module: module openacademy: loading views/openacademy.xml
INFO odoo werkzeug: 127.0.0.1 - - [16/Dec/2014 17:53:07] "POST /longpolling/poll HTTP/1.1" 200 -
**ERROR odoo openerp.addons.base.ir.ir_ui_view: Model not found: openacademy.course**
Error context:
View 'course.form'
[view_id: 1030, xml_id: n/a, model: openacademy.course, parent_id: n/a]
The model "openacademy.course" is not found, but it already exists in "models.py" !!!
This my code :
models.py :
from openerp import models, fields
class Course(models.Model):
_name = 'openacademy.course'
name = fields.Char(string='Title', required=True)
description = fields.Text()
views/openacademy.xml :
<openerp>
<data>
<record model="ir.ui.view" id="course_form_view">
<field name="name">course.form</field>
<field name="model">openacademy.course</field>
<field name="arch" type="xml">
<form string="Course Form">
<sheet>
<group>
<field name="name"/>
<field name="description"/>
</group>
</sheet>
</form>
</field>
</record>
<!-- window action -->
<!--
The following tag is an action definition for a "window action",
that is an action opening a view or a set of views
-->
<record model="ir.actions.act_window" id="course_list_action">
<field name="name">Courses</field>
<field name="res_model">openacademy.course</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">Create the first course
</p>
</field>
</record>
<!-- top level menu: no parent -->
<menuitem id="main_openacademy_menu" name="Open Academy"/>
<!-- A first level in the left side menu is needed
before using action= attribute -->
<menuitem id="openacademy_menu" name="Open Academy"
parent="main_openacademy_menu"/>
<!-- the following menuitem should appear *after*
its parent openacademy_menu and *after* its
action course_list_action -->
<menuitem id="courses_menu" name="Courses" parent="openacademy_menu"
action="course_list_action"/>
<!-- Full id location:
action="openacademy.course_list_action"
It is not required when it is the same module -->
</data>
</openerp>
__init.py__:
import models
Rename your models.py into course.py
course.py :
from openerp import models, fields
class Course(models.Model):
_name = 'openacademy.course'
name = fields.Char(string='Title', required=True)
description = fields.Text()
And change your __init__.py into this:
import models
I think model file's name should match the class name. You must make different model for each table.
A part from goFrendiAsgard answer, try with this:
Run "Update Apps List" in Odoo interface:
To see this option, you have to turn on the "Technical Feature" going to Settings –> Users, edit your user, and click on "Technical Feature".
Restart Odoo server:
I don't know how to do it in Windows, in Linux is sudo service odoo-server restart
For people facing this issue in a linux environment, can also try:
Check your module files and folder have the right owner and group:
Compare with the rest of modules and change if necesary. For example sudo chown -R odoo:odoo openacademy/
Check your module files and folder permissions:
Usually 755, so you can run sudo chmod -R 755 openacademy/