Create cron task in Odoo13 - odoo

I am working on a new module in Odoo13CE and trying to create a scheduled task with the code:
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<data noupdate="1">
<record forcecreate="True" id="electricity_charges_cron" model="ir.cron">
<field name="name">Get electricity charges</field>
<field name="model_id" ref="electricity_charges.model_electricity_charges_readings"/>
<field name="active" eval="True" />
<field name="state">code</field>
<field name="code">model.set_readings()</field>
<field name="interval_number">6</field>
<field name="interval_type">hours</field>
<field name="numbercall">-1</field>
<field name="active" eval="False" />
<field name="doall" eval="True" />
<field name="user_id" ref="base.user_root" />
</record>
</data>
</odoo>
But when install or update the module this error appears:
odoo.tools.convert.ParseError: "null value in column "activity_user_type" violates not-null constraint
Any idea how I can resolve this error? Have the mail module installed.

Related

Odoo - How to update non updateable records by XML

I have created a few companies under res.company
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="True">
<record id="partner_my_company_hk" model="res.partner" context="{'default_is_company': True}">
<field name="name">My company HK</field>
<field name="company_id" eval="None"/>
<field name="customer" eval="False"/>
<field name="is_company" eval="True"/>
<field name="street"></field>
<field name="city"></field>
<field name="zip"></field>
<field name="phone"></field>
<field name="email">info#my_company.com</field>
<field name="website">www.my_company.com</field>
<field name="image" type="base64" file="base/static/img/res_company_logo.png"/>
</record>
<record id="partner_my_company_us" model="res.partner">
<field name="name">My company US</field>
<field name="company_id" eval="None"/>
<field name="customer" eval="False"/>
<field name="is_company" eval="True"/>
<field name="street"></field>
<field name="city"></field>
<field name="zip"></field>
<field name="phone"></field>
<field name="email">info#my_company.com</field>
<field name="website">www.my_company.com</field>
<field name="image" type="base64" file="base/static/img/res_company_logo.png"/>
</record>
<record id="company_my_company_hk" model="res.company">
<field name="name">My company HK</field>
<field name="partner_id" ref="partner_my_company_hk"/>
<field name="currency_id" ref="base.USD"/>
</record>
<record id="partner_my_company_hk" model="res.partner">
<field name="company_id" ref="company_my_company_hk"/>
</record>
<record id="company_my_company_us" model="res.company">
<field name="name">My company US</field>
<field name="partner_id" ref="partner_my_company_us"/>
<field name="currency_id" ref="base.USD"/>
</record>
<record id="partner_my_company_us" model="res.partner">
<field name="company_id" ref="company_my_company_us"/>
</record>
</data>
</odoo>
This is my original res_users.xml
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="0">
<record id="base.user_admin" model="res.users">
<field name="groups_id" eval="[(4, ref('account.group_account_user'))]"/>
</record>
</data>
</odoo>
So I want to set those 2 newly created 2 companies into base.user_admin
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="0">
<record id="base.user_admin" model="res.users">
<field name="groups_id" eval="[(4, ref('account.group_account_user'))]"/>
<field name="company_id" ref="company_my_company_hk" />
<field name="company_ids" eval="[(4, ref('company_my_company_hk')),(4, ref('company_my_company_us'))]" />
</record>
</data>
</odoo>
And it is not working. But when I uninstall the module and reinstall it works.
Why? I cannot uninstall the module just to make it work in the future. What are the limitations and how to bypass the limits?
You can change the noupdate value on XML, change the desired fields and should take the change on noupdate back.
<!-- Allow updating on noupdate=True records -->
<function name="write" model="ir.model.data">
<function name="search" model="ir.model.data">
<value
eval="[('module', '=', 'base'), ('name', '=', 'user_admin')]" />
</function>
<value eval="{'noupdate': False}" />
</function>
<record id="base.user_admin" model="res.users">
<!-- change fields here -->
</record>
<!-- Revoke noupdate change -->
<function name="write" model="ir.model.data">
<function name="search" model="ir.model.data">
<value
eval="[('module', '=', 'base'), ('name', '=', 'user_admin')]" />
</function>
<value eval="{'noupdate': True}" />
</function>
External ID user_admin in base has been marked as noupdate.
And noupdate cannot be overridden.
Unless I run
UPDATE ir_model_data SET noupdate=False WHERE name = 'user_admin' and module='base';
Otherwise I won't be able to update it when I upgrade the module
More refined solution to #CZoellner 's solution is:
<function name="toggle_noupdate" model="ir.model.data" eval="['res.users', ref('base.user_admin')]"/>

Logout when print Qweb report

How can I close the odoo session after printing a qweb report?
What I want is to close session after clicking Sample Report
<?xml version="1.0"?>
<odoo>
<record id="paperformat_euro_landscape"
model="report.paperformat">
<field name="name">European A4 Landscape</field>
<field name="default" eval="True" />
<field name="format">A4</field>
<field name="page_height">0</field>
<field name="page_width">0</field>
<field name="orientation">Landscape</field>
<field name="margin_top">35</field>
<field name="margin_bottom">15</field>
<field name="margin_left">7</field>
<field name="margin_right">7</field>
<field name="header_line" eval="False" />
<field name="header_spacing">35</field>
<field name="dpi">90</field>
</record>
<report id="action_mantto_task_report"
string="Sample Report"
model="rep.oper"
report_type="qweb-pdf"
name="repop_report.report_repop_task_template"
paperformat="paperformat_euro_landscape"
/>
</template>
</odoo>

Odoo. Import data with relations

I need import employees(hr.employee object) from xml and to tie them with users(res.users object) and contacts(res.partner object). Relation with user working is good(screen below after import).
But I have problem with contacts. When system import user she authomatically create new contact which applies to user. How I can to tie this contact with employee if I don't know ID?
I tried add contact record to xml file and set relations. But in this case system creates 2 contacts. And one of them is not related to user.
Here my xml for import from my module.
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data noupdate="1">
<record id="user_test" model="res.users">
<field name="name">My Name</field>
<field name="login">my_name</field>
<field name="password">1111</field>
</record>
<!-- I tried create contact like this...
but then will be created 2 contacts
instead 1 + one of them is not related with user -->
<!--<record id="contact_test" model="res.partner">-->
<!--<field name="name">My Name</field>-->
<!--<field name="user_id" ref="user_test"/>-->
<!--</record>-->
<record id="employee_test" model="hr.employee">
<field name="name">My Name</field>
<field name="work_email">my_name#gmail.com</field>
<field name="user_id" ref="user_test"/>
</record>
</data>
</openerp>
So, my question is: How I can to set contact(which was created authomatically from user) to employee?
Try this:
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data noupdate="1">
<record id="contact_test" model="res.partner">
<field name="name">My Name</field>
</record>
<record id="user_test" model="res.users">
<field name="name">My Name</field>
<field name="login">my_name</field>
<field name="password">1111</field>
<field name="partner_id ref="contact_test"/>
</record>
<record id="employee_test" model="hr.employee">
<field name="name">My Name</field>
<field name="work_email">my_name#gmail.com</field>
<field name="user_id" ref="user_test"/>
<field name="partner_id" ref="contact_test"/>
</record>
</data>
</openerp>
Here solution:
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data noupdate="1">
<!-- at first create contact -->
<record id="contact_test" model="res.partner">
<field name="name">My Name</field>
</record>
<record id="user_test" model="res.users">
<field name="name">My Name</field>
<field name="login">my_name</field>
<field name="password">1111</field>
<!-- relation between user and contact -->
<field name="partner_id" ref="contact_test"/>
</record>
<record id="employee_test" model="hr.employee">
<field name="name">My Name</field>
<field name="work_email">my_name#gmail.com</field>
<field name="user_id" ref="user_test"/>
<!-- relation employee and contact -->
<field name="address_home_id" ref="contact_test"/>
</record>
</data>
</openerp>
In this case will be created 1 contact, 1 user and 1 employee. Employee will have relation with contact.

Customize dashboard in Odoo/Open ERP

Odoo/openerp 8 supports creating dashboard in which we can add multiple reports into it.
My question is: How can we inherit this dashboard to customize it?
For example, I want to add a button which helps clone the dashboard to another user.
It seems that this dashboard is not a usual FormView.
You can't inherit dashboards in Odoo 8.because dashboards is work like views container not usual view if you want to customize one .. just copy it's code and paste it in your module over again and customize what you need.
Try to make formview for yourself :-)
This is a good example:
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<record model="ir.actions.act_window" id="act_centiro_stocks_tree_pendientes">
<field name="name">Centiro stock</field>
<field name="res_model">stock.picking</field>
<field name="view_type">tree</field> <!-- form -->
<field name="view_mode">tree</field>
<field name="domain">[('state', 'not in', ('assigned','done'))]</field>
</record>
<record model="ir.actions.act_window" id="act_centiro_stocks_tree_procesados">
<field name="name">Centiro stock</field>
<field name="res_model">stock.picking</field>
<field name="view_type">tree</field> <!-- form -->
<field name="view_mode">tree</field>
<field name="domain">[('state', 'in', ('assigned','done'))]</field>
</record>
<record model="ir.actions.act_window" id="act_centiro_stocks_graph">
<field name="name">Operaciones Centiro</field>
<field name="res_model">gc.operaciones.centiro</field>
<field name="view_type">form</field>
<field name="auto_refresh" eval="1" />
<field name="view_mode">kanban,form</field>
</record>
<record model="ir.ui.view" id="board_view_stock_centiro_form">
<field name="name">Stock Centiro</field>
<field name="model">board.board</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Centiro Stock Dashboard">
<hpaned>
<child1>
<action string="Estado almacén Centiro" name="%(act_centiro_stocks_graph)d" colspan="2" />
</child1>
<child2>
<action string="Pedidos pendientes" name="%(act_centiro_stocks_tree_pendientes)d" colspan="2" />
<action string="Pedidos sin ubicar" name="%(act_centiro_stocks_tree_procesados)d" colspan="2" />
</child2>
</hpaned>
</form>
</field>
</record>
<record model="ir.actions.act_window" id="open_stock_centiro_board">
<field name="name">Stock Centiro Dashboard</field>
<field name="res_model">board.board</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="usage">menu</field>
<field name="view_id" ref="board_view_stock_centiro_form" />
</record>
<menuitem id="dashboard_menu" name="Dasboard custom module"
parent="cabecera_dashboard_custom_module" action="open_stock_centiro_board" />
</data>
Good luck

How to access custom module with normal user in odoo

I created a custom module and created a new user in odoo with email :1#1.com and password :1234 .When i try to login with new user webpage show this error
:"The server encountered an internal error and was unable to complete
your request. Either the server is overloaded or there is an error in
the application."
and in eclipe show this error:
"AccessError: ('AccessError', u'Sorry, you are not allowed to access
this document. Only users with the following access level are
currently allowed to do that:\n- Human Resources/Employee\n\t-
Administration/Settings\n\n(Document model: ir.ui.menu)')"
. Below is my code :
Core.py
from openerp.osv import fields, osv
class Student(osv.osv):
_name = "tt.student"
_columns = {
'name': fields.char('Code',size=20,required=True),
'ten': fields.char('Name',size=100,required=True),
'ngay':fields.date('Date',required=True),
}
Student()
main.xml
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<record id="student_tree" model="ir.ui.view">
<field name="name">Student</field>
<field name="model">tt.student</field>
<field name="type">tree</field>
<field name="arch" type="xml">
<tree>
<field string="Mã số" name="name"/>
<field string="Tên" name="ten"/>
<field string="Ngày sinh" name="ngay"/>
</tree>
</field>
</record>
<record id="student_form" model="ir.ui.view">
<field name="name">Student</field>
<field name="model">tt.student</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form>
<group col="2">
<field string="Mã số" name="name"/>
<field string="Tên" name="ten"/>
<field string="Ngày sinh" name="ngay"/>
</group>
</form>
</field>
</record>
<record id="action_student" model="ir.actions.act_window">
<field name="name">Student</field>
<field name="res_model">tt.student</field>
<field name="view_mode">tree,form</field>
</record>
</data>
</openerp>
menu.xml
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<menuitem id="main" name="Student"></menuitem>
<menuitem id="quanly" name="Quản lý" parent="main"></menuitem>
<menuitem id="sinhvien_sub" action="action_student" name="Sinh viên" parent="quanly"/>
</data>
</openerp>
You should add in the security folder the access. Add ir.access.csv file and you should define for each object the access to view, read, write and delete.