webkit report in openerp, how to make it landscape and add a header - openerp-7

I created a web kit report file, and I am aware that it is portrait by default,
how can I make it a landscape? and add header/footer to it and how can I set that up on specific reports only?
I tried to add Web kit Headers/Footers then configure my report to
'header=True' and even try header='name_of_header_footer but it did'nt work

You can add following code in your record for landscape,
<field name="html"><![CDATA[]]></field>
<field name="footer_html"><![CDATA[]]></field>
<field name="orientation">Landscape</field>
<field name="format">Letter</field>
<field eval="06.0" name="margin_top"/>
<field eval="15.0" name="margin_bottom"/>
and for header,
<field name="html"><![CDATA[
<html>
your html page
</html>
]]>
</field>
and for footer,
<field name="footer_html"><![CDATA[
<html>
your html page
</html>
]]>
</field>

You can change Portrait or Landscape at Settings > Technical > Webkit Headers/Footers.
To change which reports use which Headers/Footers, you can go to Settings > Technical > Actions > Reports. Search for the desired report and change the field "Webkit Header".
Also remember that one can set the header a report should use in the XML files:
<report
auto="False"
id="account_partner_statement"
model="res.partner"
name="account.partner_statement.webkit"
file="custom_reports_webkit/report/account_partner_statement.mako"
string="Partner Statement"
report_type="webkit"
webkit_header="custom_company_header" />
And one can also set the header when declaring a custom parser:
report_sxw.report_sxw(
'report.account.partner_statement.webkit',
'res.partner',
'addons/custom_reports_webkit/report/account_partner_statement.mako',
parser=partner_statement,
header="custom_company_header")

Related

Create Button is not showing up after following the Odoo Tutorial when creating a new module

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

Optional Dependencies in Odoo 14 CE

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>

Creating a new module in Odoo - Cannot see the module on app list after installation

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.

Importing a New Module (openacademy example) Odoo v8

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/

How to include classes in openerp views?

In my view their is an image field. so i copied it form res.partneras like below.
<field
name="image"
widget="image"
class="oe_left oe_avatar"
options="{"preview_image": "image_medium", "size": [90, 90]}"
/>
it generates an error.
but when i am using the code with no class as like below
<field
name="image"
widget="image"
options="{"preview_image": "image_medium", "size": [90, 90]}"
/>
it will not generates any error. what is the difference and how to include that class to may view?
did you activated the new v7 screen api?
for more info look at the developer memento:
https://www.odoo.com/files/memento/OpenERP_Technical_Memento_latest.pdf
(page 6)