How make my custom module visible in app switcher odoo12 through code - module

I am new to the odoo and I developed a small custom module in odoo12. The problem is I am not able to see my custom module in the app switcher page after installing the module. (Below I gave the image link, where I am not able to see the module I have created after installing).
This is the link

The first step is you must define a menuitem, if you do not set a "parent" it will be a root menu and will therefore appear in the app drawer.
<menuitem
id="model_menu_root"
name="Module Menu"
web_icon="module_name,static/description/icon.png"
groups="base.group_user"
sequence="6"
/>
You will probably want to have submenus to access your models, they will use this menu as their parent.
<menuitem name="Model Name" id="menu_1_list" parent="model_menu_root"
action="action_window"/>
And the menu refers to the window action, which controls how your model is displayed.
<record model="ir.actions.act_window" id="action_window">
<field name="name">Model Name</field>
<field name="res_model">module_name.model_name</field>
<field name="view_mode">tree,form</field>
</record>
You will need to define some security rules, otherwise the menu will not appear. These are controlled in the ir.model.access.csv file which must be declared in the __manifest__.py file. In previous versions skipping this step would be fine for testing purposes as the admin user would be able to see all models but this seems to have changed in v12 and you will need to define security rules before the menu becomes visible. Security rules are explained in the odoo developer docs https://www.odoo.com/documentation/12.0/reference/security.html
By the way, for a problem like this, usually the first place I would look would be the Odoo source code on GitHub. You can see how they have implemented the root menu and security rules on each of their modules and emulate it for your module.

Related

Custom to do app not accessible from menu

I'm new at odoo. Reading "Odoo 12 Development Essential, 4th Edition". However, I've installed Odoo 15 in AWS EC2 Instance.
Followed the books steps to create To-Do app in odoo. But its not showing in menu and I can't use it. What have I don't wrong?
First created "To-Do Item" model and added some extra fields
Created "To-do User" group and added "User Types/Internal User" in
'Inherited' Tab. Also give read/write/delete/create access to "To-do
Item" Model in "Access Rights" Tab.
Then added admin user to "To-do User" group.
Now as per the books, admin should be able to create To-do Items and all from menu.
But this item isn't available in menu. What have I done wrongly?
maybe odoo didn`t update your module, because there were some issues.
I had the same problem before, do next:
Activate developer mode in settings.
Then go to settings → technical → security rules. Find and check your access rights and record rules, maybe odoo didnt update it.
if all is right, then go to technical → interface → menu items.
find your menu record and check, if there is your group.
if all is right, maybe app is not app, check that there is a
'installable': True,
'application': True,
parameters in manifest file.
and also for example menuitems from odoo 15 docs:
<menuitem id="estate_root" name="Нерухомість">
<menuitem id="estate_objects" name="Об'єкти нерухомості">
<menuitem id="menuitem_estate_property" action="estate_property_action"/>
</menuitem>
<menuitem id="estate_settings" name="Налаштування">
<menuitem id="menuitem_estate_property_type_id" action="estate_property_type_action"/>
<menuitem id="menuitem_estate_property_tag_id" action="estate_property_tag_action"/>
</menuitem>
</menuitem>
first item in this example is root item
*P.S. if your dont see your app in apps settings, you need to push button "Update apps list"
*P.S.2 check, if there is your file in manifest data:
'data': [
'security/ir.model.access.csv',
'views/estate_property_views.xml',
],

How do I hide a `ir.actions.act_window` defined in another module

Pretty simple question. In odoo/addons/portal/wizard/portal_wizard_views.xml there is the following action:
<act_window id="partner_wizard_action"
name="Grant portal access"
binding_model="res.partner"
res_model="portal.wizard"
view_mode="form" target="new"
groups="base.group_partner_manager"/>
How do I hide it??
More Information
Other answers I've seen recommend unlinking the record completely, but not only could I not figure out the best way to do this, most importantly I would like to remove the action in such a way so that if my module is uninstalled, the action is show again as if nothing ever happened. I don't want my module doing anything to other modules that would require them to be reinstalled. Especially in this case, since the portal module is depended up by sale and account, among other critical modules.
I've also seen answers recommending just redefining the record with the same id but prefixed with the other module's name in order to override the action. In this case I guess that would look something like this:
<act_window id="portal.partner_wizard_action"
name="Grant portal access 2"
binding_model="res.partner"
res_model="portal.wizard"
view_mode="form" target="new"
groups="base.group_partner_manager"/>
However, I couldn't even get this to work. It doesn't replace the existing action in the contextual menu; instead it just adds a new action, resulting in there now being two (both "Grant portal access" and "Grant portal access 2"). And I'm not sure how I would hide the action using this method either.
Edit: I found that for some unknown reason the original action in my Odoo instance no longer had an external ID. That is why it wasn't being "overridden" when I tried redefining the record. I resolved this my uninstalling my custom module, deleting both of the actions, and then updating the portal module. This caused the action to be re-created with the external ID present again, and when I reinstalled my custom module I could then override it.
However, this doesn't solve my problem of updating the action in a "non-destructive" way. When I uninstall my custom module, changes that it made to the action persist until the original portal module is upgraded again. This is bad, because someone uninstalling the custom module would need to know that the portal module must be upgraded to revert some of the changes.
I figured it out... sort of.
First, for some reason the original partner_wizard_action from the portal module in my case had somehow lost it's external ID/ref/xml_id. I have no clue how that happened, but to resolve it I had to uninstall my custom module, delete the "Grant portal access" action and the "Grant portal access 2" action, and then upgrade the portal module. This re-created the partner_wizard_action with the correct external ID.
I could then override the action as expected with the following code:
<record id="portal.partner_wizard_action" model="ir.actions.act_window">
<field name="binding_model_id" eval="False"/>
</record>
This unbinds the action from the res.partner model, causing the action to no longer show up in the contextual menu. However, it does still exist.
This "solution" comes with a huge caveat, however. When I uninstall my custom module now, the action does not get reverted to how it was before it was overridden. So it will still be hidden, unless the portal module is explicitly upgraded again.
To get around this, I'm considering writing a uninstall_hook in my module manifest to set the action's binding_model_id back to the correct value. It sucks that there doesn't seem to be a better way to do this, however.
Edit: I was successfully able to have the action revert itself at module uninstallation using the following uninstall_hook:
from odoo import api, SUPERUSER_ID
def uninstall_hook(cr, registry):
env = api.Environment(cr, SUPERUSER_ID, {})
env.ref("portal.partner_wizard_action").binding_model_id = env.ref("base.model_res_partner").id
In case you are not aware, you would put this function in __init__.py at the root of your module and then add "uninstall_hook": "uninstall_hook" to your __manifest__.py file.
To hide an action, you can:
1- Set the binding model (binding_model_id) to False as you did.
2- Add a group with no user so the following expression is evaluated to True:
action_groups and not action_groups & user_groups
3- Add the active field (default=True) to hide action from searches then alter the _get_bindings method (because actions are fetched using an SQL query
) and change the where clause to:
where m.model = %s and active is true
4- It is also possible to alter the fieds_view_get method to filter the toolbar actions
Adding groups may require reverting changes after module uninstallation

Using an Alfresco Share Form Page, How do I upload a new file with metadata?

I'm working With Alfresco Community Edition.
Here's the code I've tried so far: Alfresco-Smalgyax.
I have created an All-in-One Project, to add a new page to the create.. menu. My Page Loads just fine.
I followed, the Adding a menu item to the "Create..." menu in DocLib tutorial, before adding a custom form field and JavaScript to the newly added share page.
I've added a custom field to upload a file to cm:content.
I've added some Javascript to get and set the cm:name and mimetype once an Upload file is chosen.
All the Metadata is correctly ingested. However, the file is not.
Previously I was successfully, able to upload a file with custom data by following the documentation: Processing multipart forms. However, that created a whole new Service endpoint and a custom page that didn't inherit the same look/feel as the rest of the web-application.
The page under create.. has the same look/feel as the rest of the site. But Upload Fails, Is there a way to leverage the Look/feel of the site and upload a file with metadata and set a custom type in Alfresco?
Clarification
The cm:content field has been customized like so:
<field id="cm:content" label-id="" mandatory="true">
<constraint-handlers>
<constraint type="MANDATORY" event="input"
validation-handler="Smalgyax.forms.validation.setNameValue" />
</constraint-handlers>
<control template="/file.ftl">
<control-param name="editorAppearance">explorer</control-param>
</control>
</field>
file.ftl sets the form input element like so:
<input id="${fieldHtmlId}" type="file"
name="${field.name}"
<#if field.disabled>disabled="true"</#if> />
additionally, file.ftl adds custom JavaScript to the page, because I was unable to get it successfully loaded as a separate file using
<forms>
<dependencies>
<js src="/set-name-field.js"/>
</dependencies>
<!-- form definition here -->
As the Alfresco documentation clearly suggests it won't supports the upload feature. The field type shows cm:content that won't accept a file to accept a file even though you have customized and added a explorer option in the code. That is the reason file is not and only content is uploading.
https://docs.alfresco.com/community/tasks/dev-extensions-share-tutorials-add-menuitem-create-menu.html
<field id="cm:content" label-id="">
<control>
<control-param name="editorAppearance">explorer</control-param>
</control>
</field>
For upload a file , you should use the html component like below,
<input type="file" multiple="" name="files[]" class="dnd-file-selection-button">
and the javascript should be same as the file-upload.js and dnd-upload.js.
http://localhost:8180/share/res/components/upload/file-upload.js
http://localhost:8180/share/res/components/upload/dnd-upload.js
Please refer the link below to upload a file through a ajax call.
https://hub.alfresco.com/t5/alfresco-content-services-forum/how-to-upload-a-file-from-a-custom-share-page/td-p/32361

How to disable/remove the "Create", "Write" operations for users in a group, but only on some views

I have a special user group who is allowed to create new res.partner instances, but only if they go through a series of steps with custom views.
On the other hand, they have restricted view possibilities on res.partner.
Thus in CRUD terminology, these users have the Create right.
On the other hand, I don't want to provide them general create rights, but only if the follow their partner wizard view.
Still, they have the Read right as well on res.partner, thus I would like to present them with a link to the tree view without a Create button.
How can I set this up?
In your case you want to hide create button from tree view.
May be this will help you...
<tree create="false">
....
</tree>
create="flase", this will be hide your create button.
You can use this one in also your kanban view & form view.
Same way you can use edit="false" to hide your edit button, and also delete="false" for delete option.
<kanban create="false" edit="false">
....
</kanban>

Create Folders in Library when submitting a list form in SharePoint 2010

I would like to know if it's possible to create folders when submitting a form in SharePoint. I created a custom SharePoint list form in Infopath and I want to add an action to the submit button to create four folders, one for each of the four doc libraries, that contains the title of the submitted item.
I see however that the custom code button is not enabled for a SharePoint list in Infopath so I cannot add any code in the background. The workflows that come out of the box also does not allow me to do it, unless I'm missing something...What other way is there to do it?
Thanks in advance for any help!!
Yes you can do this, however, it's quite tricky.
In theory, you could call the "UpdateListItems" method of the Lists.asmx web service and pass a batch statement but due the implementation of the Lists web service you cannot use it in InfoPath. That's why you need to write your own web service that wraps the UpdateListItems method so you can use it with IP.
If you do not know how to write a web service (and host it within SharePoint) please use the search function of StackOverflow or consider google - many great tutorials out there ;-)
Once you got the web service running, you need to add a service reference to the http://myserver/_vti_bin/Lists.asmx web service and then create the following method:
[WebMethod]
public void UpdateListItems(string listGuid, string xmlBatch)
{
var batch = new XmlDocument();
batch.LoadXml(xmlBatch);
//create an instance of the lists proxy client
var listSvc = listService = new ListsWebService.Lists();
//set the url of the client
listService.Url = "http://myserver/_vti_bin/Lists.asmx";
listSvc.UpdateListItems(listGuid, batch);
}
Note that if you configure the listSvc's Url hardcoded (like in this example), you need to make sure that the List, you want to add the folders to, is within the same site as the Url. If you want to make it this method more generic (which i'd suggest you do), you could simply pass the SiteCollection Url as a parameter and set listSvc.Url to SiteCollectionUrl + "_vti_bin/Lists.asmx".
Once this is set up, you can create the data connection to your newly created web service in InfoPath and configure it like this:
The field "listName" is actually the GUID of the List - you can get it via the UI by clicking "Library Settings" - "Information management policy settings" and then copy it from the address bar in your browser. Example:
{39d01277-4ba1-4589-90f8-c957b4b2dd09}
The field "XML" contains the batch script to create the folder. You can declare it staticly, or in your case, you can build it dynamically using the concat() function. This example creates a folder named "MyFolder" in the root of the Library.
<Batch>
<Method ID='1' Cmd='New'>
<Field Name='ID'>New</Field>
<Field Name='FSObjType'>1</Field>
<Field Name='BaseName'>MyFolder</Field>
</Method>
</Batch>
If you need to have sub-folders, this is possible too. This following example will create a folder named "MySubFolder" within the folder "MyFolder".
<Batch>
<Method ID='1' Cmd='New'>
<Field Name='ID'>New</Field>
<Field Name='FSObjType'>1</Field>
<Field Name='BaseName'>MyFolder/MySubFolder</Field>
</Method>
</Batch>
Then you simply add a submit button action and you're done :-)
Also note that the code above is just an example (which works though). If you use it in production be sure to add proper exception logging because you'll be needing it :-)
hope this helps!