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')]"/>
Related
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.
My custom module view looks like this
<odoo>
<data>
<record model="ir.ui.view" id="session_form_view">
<field name="name">item.form</field>
<field name="model">inventory.item</field>
<field name="arch" type="xml">
<form string="Items Form">
<sheet>
<group>
<field name="name"/>
<field name="code"/>
<field name="department"/>
<field name="state"/>
</group>
<group>
<field name="measurement" position="attributes">
<attribute name="attrs">{'invisible': [('state', '=', True)]}</attribute>
</field>
</group>
</sheet>
</form>
</field>
</record>
<record model="ir.actions.act_window" id="items_tree">
<field name="name">Item</field>
<field name="res_model">inventory.item</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<!-- <field name="context" eval="{'state':True}" /> -->
</record>
<menuitem id="main_openacademy_menu" name="Inventory"></menuitem>
<menuitem id="openacademy_menu" name="Store" parent="main_openacademy_menu"></menuitem>
<menuitem id="store_items_menu" name="Store items" parent="openacademy_menu" action="items_tree"/>
</data>
</odoo>
I have a simple model
I want to hide/show based on the department drop down. But some how for a lot of cases attrs is not working. I am begginer and using odoo 10.
Thanks
(version 9)
i need to update odoo/openerp/addons/base/res/res_currency_data.xml file
i created module added field to res.currency and added data file in my modules data folder. but my field is not updating. any suggestions?
from openerp import models, fields
class ResCurrency(models.Model):
_inherit = 'res.currency'
currency_word = fields.Char(translate=True, help='HELP')
and this is my data xml file.
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data noupdate="0">
<!-- Currencies -->
<record id="base.USD" model="res.currency">
<field name="currency_word">Dollars</field>
</record>
</data>
</openerp>
and xml for field to show up in form view.
<openerp>
<data>
<record id="view_currency_form" model="ir.ui.view">
<field name="name">res.currency.form</field>
<field name="model">res.currency</field>
<field name="inherit_id" ref="base.view_currency_form"/>
<field name="arch" type="xml">
<field name="name" position="after">
<field name="currency_word"/>
</field>
</field>
</record>
</data>
</openerp>
this is a workaround for noupdate=1
<function name="write" model="ir.model.data">
<function name="search" model="ir.model.data">
<value eval="[('module', '=', 'base'), ('name', '=', 'USD')]" />
</function>
<value eval="{'noupdate': False}" />
</function>
<record id="base.USD" model="res.currency">
<field name="currency_word">Dollars</field>
</record>
<function name="write" model="ir.model.data">
<function name="search" model="ir.model.data">
<value eval="[('module', '=', 'base'), ('name', '=', 'USD')]" />
</function>
<value eval="{'noupdate': True}" />
</function>
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.
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