Odoo: How to add custom category name to app module's search panel? - odoo

For example i have app with
category = "custom_category"
How can i add this category to my search panel in app module ?
When I created a category, I thought it would come here automatically, but it didn't.
I found the file, where these categories are defined:
15.0/odoo/odoo/addons/base/data/ir_module_category_data.xml
But something is not right here! When I delete a record from here, for example:
<!-- <record model="ir.module.category" id="module_category_human_resources">-->
<!-- <field name="name">Human Resources</field>-->
<!-- <field name="sequence">45</field>-->
<!-- </record>-->
And update the base module, this (Human Resources) field is still in this menu !?
Why it is not deleted? Any advice?

Model 'ir.module.category' doesn't have delete access rights (ref https://github.com/odoo/odoo/blob/a7f7233e0eae8ee101d745a9813cba930fd03dcb/odoo/addons/base/security/ir.model.access.csv#L20). So once a record is created from the xml file, it will not delete if you comment that code line.
You can directly delete it from the database using delete query.

Odoo will only show categories that do not have a parent and that one of the subcategories is linked to a module.
If the category_id field is defined in the search panel, Odoo will use a custom domain:
domain = [('parent_id', '=', False), ('child_ids.module_ids', '!=', False)]
To show the custom category in the search panel:
First, define the module category as follows:
<record model="ir.module.category" id="module_custom_category">
<field name="name">custom_category</field>
<field name="sequence">99</field>
</record>
<record model="ir.module.category" id="module_child_category">
<field name="name">child_category</field>
<field name="parent_id" ref="module_custom_category"/>
</record>
Then set it in a module __manifest__.py file:
'category': 'custom_category/child_category',
Why Odoo did not remove the category after commenting the XML definition?
Odoo will create two categories with the same name (custom_category) with the following XML IDS:
base.module_category_custom_category
stack15.module_custom_category
And use the first one to show it in the search panel.
When you comment record XML definition and upgrade the module, Odoo will remove the category using the module name as a prefix in its XML id (stack15.module_custom_category) and keep the base category (base.module_category_custom_category), so the custom category will be visible even if you uninstall the module.

Related

How to give user groups(XML) in the model ir.actions.server odoo 12?

I used this xml code to add a button inside the 'Action',But i need to restrict the button to some user groups,
<record id="specialist_no_show_action" model="ir.actions.server">
<field name="name">No Show </field>
<field name="type">ir.actions.server</field>
<field name="binding_model_id" ref="second_opinion.model_consultation"/>
<field name="model_id" ref="second_opinion.model_consultation"/>
<field name="state">code</field>
<field name="code">
action = model.update_no_show()
</field>
</record>
The ir.actions.actions get_bindings method will try to retrieve the list of actions bound to the given model and discard unauthorized actions then read action definitions.
The method will use groups_id field to check if the user may not perform an action.
groups_id
Many2many field to the groups allowed to view/use the current report
So a groups_id field is added to ir.actions.report to allow groups to view/use the current report
Unfortunately, the groups_id field is not implemented in ir.actions.server
Fortunately, the get_bindings method is implemented in the ir.actions.actions model which is the base model for both models ir.actions.report and ir.actions.server, so to use the same logic in server actions just add a groups_id field in ir.action.server and use it from the XML definition to restrict access to some groups.
Use the groups_id field for server action:
Inherit server action model and add the groups_id field:
class IrActionsServer(models.Model):
_inherit = 'ir.actions.server'
groups_id = fields.Many2many('res.groups', 'res_groups_server_rel', 'uid', 'gid', string='Groups')
Then set the groups_id field value from XML, the following example will use the special commands format to add the Administration/Access Rights group to the groups_id field:
<field name='groups_id' eval="[(4, ref('base.group_erp_manager'))]"/>
I don't think it is possible to restrict its visibility in the action menu, but as a workaround you could do the following in the code of the server action:
if not env.user.has_group('base.group_erp_manager'):
raise Warning("You do not have access to trigger this action")
Replace "base.group_erp_manager" with your user group's XML ID.

How to display my module in one of multiple website Odoo?

I have two websites in Odoo.
Site 1: www.A.com
Site 2: www.B.fr
I created a module but I would like it to be visible only in website 2. But when I install it, it appears in both sites. I must then change the views manually in Odoo so that my view is visible on site 2.
I tried to put "website_id: 'B' in manifest.py but it doesn't work.
Where should I report please? I searched but I can't find a solution ...
Thank you.
You can edit your view or template and test for the website id to add your content, for example:
<template id = "test" name="test" inherit_id="test.test_view" priority="16">
<t t-if="website.id == 1">
<!-- add or edit the content that you want-->
</t>
</template>
You can specify the value of website_id field when you define the view or set its value by inheriting an existing view.
You will need the external id of website2(website.website2) and the external id of an existing view in case you need to use inheritance.
Specify the value in the view definition:
<record id="MODEL_view_TYPE" model="ir.ui.view">
<field name="name">NAME</field>
<field name="model">MODEL</field>
<field name="website_id" ref="Website_External_Id"/>
<field name="arch" type="xml">
 
Inherit an existing view and specify the website_id field value:
<record id="VIEW_External_ID" model="ir.ui.view">
<field name="website_id" ref="Website_External_Id"/>
</record>

openerp odoo v11.0 invalid model name error

i am trying to build an odoo module named kroshu for stock managment
i have wrote the needed models and the views
after i try to install my module odoo server shows this message
File "C:\Program Files (x86)\Odoo 11.0\server\odoo\addons\base\ir \ir_actions.py", line 128, in _check_model
raise ValidationError(_('Invalid model name %r in action definition.') % action.res_model)
odoo.tools.convert.ParseError: "Invalid model name 'kroshu.product' in action definition.
None" while parsing file:/c:/program%20files%20(x86)/odoo%2011.0/server/odoo/addons/kroshu_khalil_kasmi/data/actions.xml:5, near
<record model="ir.actions.act_window" id="action_kroshu_product">
<field name="name">Product</field>
<field name="res_model">kroshu.product</field>
<field name="view_mode">tree,form</field>
</record>
my module is named Product.py :
from odoo import models,fields
class Product(models.Model):
_name = 'kroshu.product'
product_id = fields.Char("product id",required =True)
product_name = fields.Char("product name",required = True)
product_description = fields.text("product description")
product_type = fields.One2many("product.type","product_type_id",string="type")
product_category = fields.One2many("product.category","product_category_id",string="category")
quantity_on_hand = fields.Integer("quantity on hand",required =True)
forcasted_quantity = fields.Integer("forcasted quantity")
location_in_stock = fields.Char("product location in stock")
barcode = fields.text("barcode")
vendor = fields.One2many("product.vendor","vendor_id",string="vendor/manufacturer")
cost = fields.Float("cost")
stock = fields.One2many("kroshu.stock","stock_id",string="in stock")
my action_views.xml file :
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<menuitem name="Kroshu" id="kroshu_root_menu"/>
<record model="ir.actions.act_window" id="action_kroshu_product">
<field name="name">Product</field>
<field name="res_model">kroshu.product</field>
<field name="view_mode">tree,form</field>
</record>
<record model="ir.actions.act_window" id="action_kroshu_product_category">
<field name="name">Product Category</field>
<field name="res_model">product.category</field>
<field name="view_mode">tree,form</field>
</record>
........ still more lines
my __ init __ .py file :
from . import category
from . import product
From what you have stated above. The issue is likely that in your __init__.py file you are importing product however the file is called Product.py. I also am not sure of the indentation within Product.py however this may just be formatting of what was copied and pasted into stack overflow.
When writing a new module, for debugging the general setup, it may help to simplify first and then add step by step, keeping things working.
In your case, first create one model with one field (like name) and get that to work. Then, add more simple fields, a view and an action. Make sure you can create records for your new model.
Then, adding relational fields, make sure to include the dependencies in the manifest file where the target models are (in your case, product for product. product etc.)
Finally, make sure your second model kroshu.stock needs to exist, too, following the same methodology.
You have an error inside your model definition:
barcode = fields.text("barcode")
instead of :
barcode = fields.Text("barcode")
change text to Text and your code 'll become nice.
Second Solution:
try to rename your model name, change
_name = 'kroshu.product'
for example like:
_name = 'kroshuproduct'
Odoo commonly uses this expression to specify that the model product is inside de module name kroshup for example.
This error mostly occur when you have and error inside your Model
definition. to detect your Error, comment all fields and test every
fields alone.
Hope this help you! Great!

How to link Leads (emails) to Marketing emails sent in Odoo v8?

I have Leads and all my leads have emails set. Now I have sent emails to leads with "Mass Mailings" from "Marketing". But now when I click on my lead I do not see any link between the Lead (email) to emails I have sent with "Mass Mailings".
Is there a way to make a link between Lead (email) to email I have sent?
The information about sent emails is available trough the model mail.mail.statistics. In this model you have everything you need. The following fields may be of interest for your task:
model - as emails may be related to any Odoo model, this field tells you to which model was related the email. You are interested in records with crm.lead in this field
res_id - the id of the corresponding model instance. In your case this fields links you to the id of your lead.
mail_mail_id_int - the id of the objects of type email.email - the emails themselves
etc.
You can use this to create a list of emails related to a lead and show them in the crm lead form.
To do that, create a new Odoo module, extend the crm.lead object adding a One2many relation to the mail.mail.statistics model and extend the crm.lead view to show this new field.
For instance, in a file called models/lead.py in this new module, put the following:
from openerp import models, fields
class crm_lead(models.Model):
_inherit = 'crm.lead'
emails = fields.One2many(comodel_name='mail.mail.statistics',
inverse_name='res_id',
domain=[('model', '=', 'crm.lead')])
crm_lead()
Respectively, to extend the view, create a file views/lead_view.xml like this:
<?xml version="1.0"?>
<openerp>
<data>
<record model="ir.ui.view" id="mail_crm_stats.crm_lead_form">
<field name="name">mail_crm_stats.crm_lead.form</field>
<field name="model">crm.lead</field>
<field name="type">form</field>
<field name="inherit_id" ref="crm.crm_case_form_view_leads"/>
<field name="arch" type="xml">
<xpath expr="//notebook/page[#string='Extra Info']"
position="after">
<page string="Emails sent">
<group name="emails">
<div>
<field name="emails" nolabel="1"
class="oe_inline"/>
</div>
</group>
</page>
</xpath>
</field>
</record>
</data>
</openerp>
Now you should see additional tab 'EMails sent' in your lead form. Of course, this is just and example and the module may be improved to show better information about the sent emails. As the case is interesting I may commit soon a new version in the github repository I created for the purpose..
You can download the entire module and test it from my github repository like this:
git clone https://github.com/andreiboyanov/odoo-mails_crm_stats mails_crm_stats
In V8 there is a fields between leads and Marketing Campaign See in any Lead > Extra Info (tab) > Marketing, You can manually add your campaign to that, but if you need to automatically sync then you need to create a new module for that, but just for now you can manually put entry.You can view various modules on here.

How to make tabindex in openerp fields

I want to change the tabindex in a form in opererp
how can I change it in the xml file or the python code
I am using openerp 6.1
example to what I need
in sales order form ,user want to change the focus of the element using tab button
he need to write first the order reference field then go to customer service field using a tab button,but when I press tab I go to the date button not the custom service even that the date button has a default value
Thanks
You can inherit and change both the models (defined in python files) and views (defined in xml files). More details about inheritance can be found here Object Inheritance
and Inheritance in Views
you can overwrite the original xml arch in your view and change the sequence of pages as per your requirement
like:
<record id="**account.invoice_supplier_form**" model="ir.ui.view">
<field name="name">account.invoice.supplier.form</field>
<field name="model">account.invoice</field>
<field name="priority">2</field>
<field name="arch" type="xml">
<form string="Supplier Invoice" version="7.0">
as shown above you can write the same xml arch as define in account for supplier invoice,
and you can now change sequence of pages
hope this help