I have developed a custom Module in OpenERP 7, My administrator user can only see this module.
1-How can I give access to normal users to my custom modules?
2-What are the steps to solve this problem.
Please give a detailed example.
Create a one Security folder which has below two files. For example,
test_security.xml and
ir.model.access.csv
security/test_security.xml file
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data noupdate="0">
<record model="ir.module.category" id="module_category_name_test">
<field name="name">Management</field>
<field name="sequence">7</field>
</record>
<record id="group_name_test_user" model="res.groups">
<field name="name">User</field>
<field name="category_id" ref="module_category_name_test"/>
<field name="implied_ids" eval="[(4, ref('base.group_user'))]"/>
</record>
<record id="group_name_test_manager" model="res.groups">
<field name="name">Manager</field>
<field name="category_id" ref="module_category_name_test"/>
<field name="implied_ids" eval="[(4, ref('group_name_test_user'))]"/>
<field name="users" eval="[(4, ref('base.user_root'))]"/>
</record>
</data>
</openerp>
After do this Management Option show with two selection value like User and Manager in setting => Users => Access Rights => Application
Now turn for security/ir.model.access.csv
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
unique_id, test.name, model_test_name, group_name_test_user, 1,1,0,0
unique_id, test.name, model_test_name, group_name_test_manager, 1,1,1,1
test.name is a table name.
Example of csv file, how to create? Where
Fields => Value => Description
id => access_testing_for_user => id must be unique.
name => testing.for.user => name is given as we want.
model_id:id => model_test_name => model_id:id is given like model_our_class_name.
group_id:id => group_name_test_user => group_id:id is xml id of above we create like for User and Manager.
perm_read => 1 for True and 0 for False for read record.
perm_write => 1 for True and 0 for False for write record.
perm_create => 1 for True and 0 for False for create record.
perm_unlink => 1 for True and 0 for False for delete record.
NOTE
These two files .xml and .csv must be listed in __openerp__.py as other view files are given.
Related
Please i want to establish access rights for my module, so I modify the file csv I try to install the module, but this error appears at the time of installation of the module:
File "/home/omar/odoo/odoo11/odoo/modules/loading.py", line 95, in _load_data
tools.convert_file(cr, module_name, filename, idref, mode, noupdate, kind, report)
File "/home/omar/odoo/odoo11/odoo/tools/convert.py", line 785, in convert_file
convert_csv_import(cr, module, pathname, fp.read(), idref, mode, noupdate)
File "/home/omar/odoo/odoo11/odoo/tools/convert.py", line 832, in convert_csv_import
raise Exception(_('Module loading %s failed: file %s could not be processed:\n %s') % (module, fname, warning_msg))
Exception: Module loading moduletest failed: file moduletest/security/ir.model.access.csv could not be processed:
No matching record found for external id 'groups_group1' in field 'Group'
No matching record found for external id 'groups_group2' in field 'Group'
One of the things that make this error occur is when you don't respect the order of security files, you have to put your .xml file that is related to security before the .csv file in your __ manifest __.py
Here's a simple example:
'data': [
'views/security.xml',
'security/ir.model.access.csv',
# ... other includes ...
]
this is a sample code for category and group
<record model="ir.module.category" id="module_category_stock_quotation_request"> -->
<!-- <field name="parent_id" ref="module_category_localization" /> -->
<!-- <field name="name">Stock Transfert Request</field>
<field name="visible" eval="0" />
</record>
<record id="group_stock_quotation_request_user" model="res.groups">
<field name="name">User</field>
<field name="implied_ids" eval="[(4, ref('base.group_user'))]"/>
<field name="category_id" ref="module_category_stock_quotation_request"/>
</record>
<record id="group_stock_quotation_request_manager" model="res.groups">
<field name="name">Manager</field>
<field name="implied_ids" eval="[(4, ref('transfert_request.group_stock_quotation_request_user'))]"/>
<field name="category_id" ref="module_category_stock_quotation_request"/>
</record>
I want to write a custom module to replace mail templates.
Those templates are included in base Odoo addons, such as sale:
The sale.order template ìs provided by the file /sale/data/mail_template_data.xml
This template is as follows:
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<!--Email template -->
<record id="email_template_edi_sale" model="mail.template">
<field name="name">Sales Order - Send by Email</field>¬
...
</odoo>
As the custom module wants to replace this standard base template:
Can a record with the same id be provided by the custom module to replace this mail template?
What shall be writte in <data noupdate>?
What will happen if module sale is updated?
Odoo 10 community edition.
For replacing the Email Templates just add the addon name in-front of the template name followed by dot(.) and make sure that you delete the default email template from the front end. Then update your custom addon. This will replace the old template.
Example:
<record id="sale.email_template_edi_sale" model="mail.template">
<field name="name">Sales Quotation</field>
<field name="email_from">${(object.user_id.email and '%s <%s>' % (object.user_id.name, object.user_id.email) or '')|safe}</field>
<field name="subject">${object.company_id.name} ${object.state in ('draft', 'sent') and 'Quotation' or 'Order'} (Ref ${object.name or 'n/a' })</field>
<field name="partner_to">${object.partner_invoice_id.id}</field>
....
....
</record>
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<!--Email template -->
<record id="email_template_edi_sale" model="mail.template">
<field name="name">Sales Order - Send by Email</field>
...
</odoo>
Please add your code to
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<delete model="mail.template" search="
[('id','=',ref('sale.email_template_edi_sale'))]"/>
<!--Email template -->
<record id="sale.email_template_edi_sale" model="mail.template">
<field name="name">Sales Order - Send by Email</field>
...
</odoo>
This will delete the original mail template and add a new template with the same ID so that the odoo functionlity is not disturbed.
Don't delete original template, you will lose the original module field and somethings will stop to work. Instead change noupdate value in ir.model.data for your template.
To do this automatically on module update:
Modify model 'ir.model.data' and add an allow_update method, creating a ir_model_data.py in models folder (modify __init__.py to include new file):
from odoo import models, fields, api
class IrModelData(models.Model):
_inherit = 'ir.model.data'
#api.model
def allow_update(self, module, name, model):
self.search([('module', '=', module), ('name', '=', name), ('model', '=', model)])[0].noupdate = False
Add function call element to allow_update before your record update and pass the original module name, external_id and 'mail.template':
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="0">
<function model='ir.model.data' name='allow_update'>
<value>sale</value>
<value>email_template_edi_sale</value>
<value>mail.template</value>
</function>
<record id="sale.email_template_edi_sale" model="mail.template" >
<field name="body_html" type="html">
<div style="margin: 0px; padding: 0px;">
<p style="margin: 0px; padding: 0px; font-size: 13px;">
% set doc_name = 'quotation' if object.state in ('draft', 'sent') else 'order'
Dear ${object.partner_id.name}
I was trying to add a extra field in hr module i.e in hr.employee object by inheritance but when I'm adding that field ,in Hr module employee form my given field is not displayed .So pls help. All I want to do is create another seperate module so whenever that module is installed then that column should appear.(my field jdate should appear after coach_id field)
class joining_date(osv.osv):
_name="joining.date"
_inherit = "hr.employee"
_columns={
'jdate':fields.date('Joining date'),
}
joining_date()
xml part:
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<record id="view_join_date" model="ir.ui.view">
<field name="name">Join_date</field>
<field name="model">joining.date</field>
<field name="inherit_id" ref="hr.view_employee_form"/>
<field name="arch" type="xml">
<data>
<xpath expr="//form/sheet/notebook/page/group[1]/group[2][#name='coach_id']" position="after">
<field name="jdate"/>
</xpath>
</data>
</field>
</record>
openerp file:
{
'name': 'HR join date',
'version': '1.0',
'category': 'Tools',
'description': """ To add extra join date field""",
'author': 'Greywind',
'website': 'http://www.greywind.com',
'depends': ['hr','base', 'account_accountant'],
'data': [
'joindate_view.xml'],
'demo': [],
'installable': True,
'auto_install': False,
}
I think your XML should look like this:
<record id="view_join_date" model="ir.ui.view">
<field name="name">Join_date</field>
<field name="model">joining.date</field>
<field name="inherit_id" ref="hr.view_employee_form"/>
<field name="arch" type="xml">
<field name="coach_id" position="after">
<field name="jdate"/>
</field>
</field>
</record>
Try to -name and -inherits field as the same id. if its so you can add your field in to the inherited module.
Then ref=base module view idand also if you want all the fields of your base module to your new module then you just change ref = **base module view id . new module view id you should create the view for the new module with all the fields you needed from base & new field.
You should refer MrEthan Furman xml code.
I have developed a custom Module in OpenERP 7, My administrator user can only see this module.
1-How can I give access to normal users to my custom modules?
2-What are the steps to solve this problem.
Please give a detailed example.
Create a one Security folder which has below two files. For example,
test_security.xml and
ir.model.access.csv
security/test_security.xml file
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data noupdate="0">
<record model="ir.module.category" id="module_category_name_test">
<field name="name">Management</field>
<field name="sequence">7</field>
</record>
<record id="group_name_test_user" model="res.groups">
<field name="name">User</field>
<field name="category_id" ref="module_category_name_test"/>
<field name="implied_ids" eval="[(4, ref('base.group_user'))]"/>
</record>
<record id="group_name_test_manager" model="res.groups">
<field name="name">Manager</field>
<field name="category_id" ref="module_category_name_test"/>
<field name="implied_ids" eval="[(4, ref('group_name_test_user'))]"/>
<field name="users" eval="[(4, ref('base.user_root'))]"/>
</record>
</data>
</openerp>
After do this Management Option show with two selection value like User and Manager in setting => Users => Access Rights => Application
Now turn for security/ir.model.access.csv
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
unique_id, test.name, model_test_name, group_name_test_user, 1,1,0,0
unique_id, test.name, model_test_name, group_name_test_manager, 1,1,1,1
test.name is a table name.
Example of csv file, how to create? Where
Fields => Value => Description
id => access_testing_for_user => id must be unique.
name => testing.for.user => name is given as we want.
model_id:id => model_test_name => model_id:id is given like model_our_class_name.
group_id:id => group_name_test_user => group_id:id is xml id of above we create like for User and Manager.
perm_read => 1 for True and 0 for False for read record.
perm_write => 1 for True and 0 for False for write record.
perm_create => 1 for True and 0 for False for create record.
perm_unlink => 1 for True and 0 for False for delete record.
NOTE
These two files .xml and .csv must be listed in __openerp__.py as other view files are given.
I am in the process of debugging something in OpenERP using Python 2.7.3. The debugger seems to get out of sync with the code when stepping through with the Next (n) command. See Code and output below. I have the same problem with Python 2.6.5. I have never experienced this before using Python pdb.
I believe the problem may be related to the way OpenERP calls my method through a Python exec() statement by reading the code field in the OpenERP XML below. Is possible that calling Python code constructed dynamically and called via exec() is confusing the pdb debugger?
If this is the case is there a work around?
CODE called via this OpenERP action below:
<record id="action_wash_st_method1" model="ir.actions.server">
<field name="type">ir.actions.server</field>
<field name="condition">True</field>
<field name="state">code</field>
<field name="model_id" ref="model_view_tree_display_address_list"/>
<field eval="5" name="sequence"/>
<field name="code">
action = self.view_calc_sales_tax(cr, uid, context)
</field>
<field name="name">wash state action request</field>
</record>
<record model="ir.values" id="action_wash_st_tax_trigger_method1" >
<field name="key2" eval="'tree_but_open'" />
<field name="model" eval="'view.tree.display.address.list'" />
<field name="name">Method1 Wash State</field>
<field name="value" eval="'ir.actions.server,%d'%action_wash_st_method1"/>
<field name="object" eval="True" />
</record>