Odoo11 - Restrict user assignment to project team members - project

I downloaded the .exe file of the community edition of odoo 11, installed it on a windows server and configured rules, that projects can only be seen by users who are assigned to the project as team members.
That works fine!
Now, in a task I want to restrict the options in the "assigned to" dropdown of a task: In the dropdown I want to see only users, who are actually assigned to that project. At the moment I can see all existing users and can assign the task to any of them.
In the form view I tried to restrict the list as follows by adding the domain attribute:
<field name="user_id" class="o_task_user_field" domain="('user_id','in', [project.members])" />
This gives an error on save.
Field 'project' used in attributes must be present in view but is missing
Update: 2. approach:
I tried to update the field user_id in model project.task and set the domain as follows:
('project_id.members','in', [user.id])
But I got the error (translated from german): you cannot make changes in a basic field!
How can I limit the options in the dropdown (without making code changes as I don´t have the code forked from github)?
Any help appreciated!
Thanks

For this you just need to update one onchange and in that add domain. No need to add it from xml. There is by default onchange_projectmethod is there. In that you just inherit it and add one line..
result.update({'domain':{'user_id':[('project_ids','in',project_id)]}})

Related

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

Sharepoint 2010 custom content type does not show in list creation screen

I have a content type that was created by another developer long ago. After deployment, the content type does not show up in the list creation screen. Even when filtering lists and custom types. It's just not there anywhere. The feature is successfully deployed and if I do a template of the list from another farm, and then create the list from that template everything works as expected.
Thanks for anyone that knows what I might be missing here.
The answer was that it needs to have a list definition added to the project.

Linking 2 fields in OpenERP

I'm new to OpenERP and not really getting how to do this.
What I need is a new field in the purchase requisition form called “project”. A user should be able to select to which project a quotation belongs. Then if the requisition is accepted and a quotation is formed this field should also be loaded to that form (with the correct project, that was selected on the requisition).
I’ve been reading a lot on the internet, but either can’t find the answer or I just don’t understand it.
I read some stuff about needing to create your own module to customize the forms, and found some step to step explanations. But then I still don’t get how to link the fields.
So if someone could give me an answer on how to do this, or direct me to an (easy to understand) explanation. That would be great.
yes you should make a custom module for this. you will find enough tutorials on how to do that on the internet (e.g. http://www.pixelite.co.nz/article/adding-additional-fields-using-custom-module-openerp-7).
in this custom module you have to extend the model purchase.order with one new field, call it like project_id. it will be a many2one type of field and so called other object (relation) will be either project.project or project.task.
after that you have to extend the form view (and maybe the tree view) of purchase.order (xml_id: purchase.purchase_order_form). just add your field where you want to have it ;-)
now get it done :-P i hope i could've helped you :-)
edited:
Ok, you if you got Admin rights on the OpenERP System you can try it the in-system-way. just open the models menu unter settings -> technical -> database structure
search for purchase.order and open the model form view. now edit the record and add a new field like (scroll down and click "add new item"):
now you have to create a new view, to extend the original one. go to settings -> technical -> user interface -> views.
create a new one like this:
that's it. if you open a purchase order, you will see the project field right under the supplier reference.

DNN 7 Custom Profile Property with database validation

I'm using DotNetNuke 7 for my CMS. I created a custom profile property for zip codes. Does anyone know how to add custom validation for the data entry before allowing the user to register.
Thanks
I don't think DNN allows this in custom properties, you'll likely need to wire something up yourself to make this happen. You might be able to add some custom jquery to the registration page that does some webservice calls to check and validate a property, but I haven't tried that before so it would probably be a lot of trial and error until you get it working right.
Click on the pencil next to the property you created if its only one zip code then in the valid expression area put the zipcode ex:08109 of you wanted to have it at two zipcodes lets say 08109 and 08110 then you could use a validation expression something like this:
^[0]{1}[8]{1}[1]{1}[0-1]{1}[0-9]{1}$

Adding a custom field type to SugarCRM?

I'm trying to add a custom field type to our SugarCRM 6.2 instance. I want to add an "email link" type field. I want it to function like the URL field, but prefix every address with "mailto://" prefix instead of "http://".
It will be good if that field type is available in studio while creating new fields or in minimum, some custom code to achieve it.
What I did up to now:
- I've copied include/SugarFields/Fields/URL to include/SugarFields/Fields/Email
- In modules/ModuleBuilder/language/en_us.lang.php I've added a title for the email field
But unable to get anything working. Any help?
First of all you do not want to make any coding changes outside of the custom directory. Doing so outside of this directory is not upgrade safe.
Create a custom fields directory in your custom folder
Create new template files (.tpl) for your custom field
then you can just add a regular textfield in studio
then edit your viewdefs in your custom directory
in your tpl file concatenate the mailto:// to your text and just add the persons email address and it will take care of the rest for you
why you need custom field type for such small functionality? Just add your custom JS file in editviewdef.php. Then use some jQuery selector to perform certain action. For detail view, you can use view.detail.php to add required text in run time.
This will help you to store less data in database and display more in frontend.