Odoo drop down action for a specific domain - odoo

In Odoo13 I have an act_window action for multiple records in list (tree) view. It is supposed to change ownership on leads using a custom wizard. The ownership can only be changed on leads, not on opportunities.
I would like to hide this action when listing opportunities. As the binding model for this action is "crm.lead" this action shows also for opportunities because they share the same model. For now I solve this in a Python code [pseudocode] if type != 'lead': raise UserError(...).
So I can avoid the unallowed ownership change on an opportunity but it would be more user friendly if the action is hidden for opportunities. I tried to apply domain: domain="[('type', '=', 'lead')]" in the definition of act_window but with no effect. Is it actually possible to control visibility of ir.action using a domain?

Related

How can I create internal user using my custom module in odoo15?

I don't want to use 'users' menu item and want to manage users from another menu item named 'Merchant' and only a specific user group data will be there and while creating new record I want to set a specific user_group. Is there any approach for that?
You can simply add the menu directly under your module. Get the menu for res.users and put where ever you want. Don't forget to add dependency to base.
While doing that you can add a domain to the menu item and filter according to your needs.
Also put that domain into the context of the menu with giving a default value same as the domain. That is, you need to put the required settings in the context like {default_FIELD_NAME: VALUE}. You need to use the default_ prefix for it to work. That way when creating a new user from your menu the context will get the default value and set accordingly. However, if it is not a readonly field, user may change the value. There are two ways to avoid that:
i. create your own form using the res.users and design it the way you like it with default values.
ii. inherit the view of res.users and change the related field to be readonly if a certain context value is passed. Then you can call the view with context let's say {readonly_group_x: True} and it should work. Also you may need to make sure that force_save="1" is set since it may not save the readonly field.
These are the basic steps of accomplishing what you have described. However, working with res.groups can be challenging depending on what you want to do. You may need to tweak or even end up creating your own view with the desired effect.

Aurelia Validation rule (bound to model) does not fire on subsequent activations of a view model

I am trying to expand on the Aurelia Contact Manager Tutorial. Specifically: adding email validation to the contact-details.html view. I have followed the examples in the Validation: Basics documentation and on first pass it worked as expected: Launch application, select a contact from the contact-list module, then update the email to something invalid by removing the '#', then tab away. The validation rule fires and the error message is displayed.
However, if after launching the application I select a first contact followed by a second, hence triggering a second activation of the contact-details module, then the validation rule does not fire.
I have tried a validationController.reset() on activate of the contact-detail and while this will remove any 'old' error messages, the on blur validation will still not fire.
I have tried the two different methods of creating the validation controller (using NewInstance.of(ValidationController) vs ValidationControllerFactory) but both yield the same result.
If, after navigating to a second contact and 'breaking' the validation, I then refresh the browser and reload the page then the validation works again. Until I choose another contact from the list which will then break it again.
I am new to Aurelia and JavaScript frameworks in general and I'm not sure if this is a bug or there is something extra required to handle re-routing to the same page.
That's a good question. There are a couple of things that may be catching you out. I've created a Gist which includes the necessary file modifications to get this working:
https://gist.github.com/freshcutdevelopment/170c2386f243e7095e276811dab52299
Gotchas
Because the view-model you're using for validation is not the backing view-model for the contact-detail.html view file you'll need a separate class which you'll apply the validation rules to. Although it sounds like you've already nailed this part, I'll include it for completeness. You can create this class like so:
export class Contact {
email= '';
}
You can then apply the validation rules to this class as follows:
ValidationRules
.ensure(a => a.email).required().email()
.on(Contact);
The last possible missing puzzle piece here is that you'll need to hook into the screen activation life-cycle hook deactivate() and reset the validation context. This will force the BootstrapValidationRenderer to remove the validation styles from your view.
deactivate(){
this.controller.reset();
}
Validation Workflow
The steps are as follows:
Inject the controller
Add the validation renderer to the controller
Create the validation model (only needed if the model you want to validate is not the view-model that backs your view)
Apply the validation rules to the model
Determine when to re-set and execute the validation (in this case on the deactivate life-cycle hook.
Apply the validation binding behavior to the view

New module for personal collection/receive with possibility to choose shop (pickup to store)

I want to add possibility for clients to receive orders personally in one of our shops. I tried to find some module which gives possibility to select in which shop they want to receive order but I haven't found anything for free. Because of that I want to create new module for it. What's more I'm totally new in prestashop and I don't know where to start or how to create this module. I spend two-three days reading how to do it and these are my assumptions:
New carrier module can be created by extending CarrierModule class.
I read some articles / documentation about hooks.
I have created my first carrier module by editing module attached in this article http://www.prestashop.com/blog/en/carrier_modules_functions_creation_and_configuration/.
What I achieved is that I installed module and used hook 'BeforeCarrier' to add some layout to page after selecting my carrier.
This is how my carrier should work:
It should be a part of carrier list so customer is able to select it.
If carrier is not selected nothing hapens. If carrier is selected by customer then button 'Choose shop' should be shown.
After pressing button 'Choose shop' new window should be show with addresses of our shops (instead of new window it may be placed somewhere in current page).
Window with shop adresses will contain list of addresses with radiobuttons and button to confirm selection.
After confirmation of selection window will be closed and address should be shown as a part of carreir.
E-mail with confirmation will contain information in which shop customer can collect order.
Suppose that addresses will be hardcoded in php code.
These are my questions:
I created new carrier module so I assume it works correctly (as described here http://www.prestashop.com/blog/en/carrier_modules_functions_creation_and_configuration/).
How to add new button 'Choose shop' near selected carrier?
Can I use hooks to add 'Choose shop' button?
Where should I remember choosen shop address? Has 'Carrier' class place for it?
How to add shop address to e-mails? Should I edit layouts? Does e-mail layout contain place for it or do I need to add new 'placeholder' for it?
How to show chosen address on admin side?
To describe my problem more detail I have created few scenario (see attachment).
I will be greatful for any help.
I've posted the same question on prestashop forum.
These example are usually old and poorly written. They lack structure. But for your purpose I suppose they're ok.
Use hookDisplayCarrierList($args). Check $args to see which carrier has been selected, then return <select> element which you
shop addresses. This hook is triggered every time a user selects a carrier and is return via Ajax. Therefore, you may not use ajax here.
You should include you javascript in a file. Use hookDisplayHeader to detect when to insert this file into your page:
public function hookDisplayHeader(){
$propExists = property_exists($this->context->controller, 'php_self');
if($propExists){
$controllerName = $this->context->controller->php_self;
if(in_array($controllerName, array('order', 'order-opc'))){
// $this->context->controller->addJS($this->_path.'js/customcarrier.js');
This Javascript file should check whether a valid shop has been selected before going to the next step;
Because your Js code is in a file and the hookDisplayCarrierList cannot contain any JavaScript (because it returns Ajax),
you should also make use of hookDisplayBeforeCarrier. Here you could insert you custom carrier ID - this way you'd know
when to check for errors with your JS file.
Same question as #2.
The correct way to save the information would be to add a model. CustomCarrierSelectedAddress - or something like it.
It would have these columns: id_cart, id_shop_address;
The way you implement shop addresses is up to you. You may define them as constants or even make a new model for them.
Models arent that hard to create, you just need to declare class properties, static variable $definition that's it.
You may add you own methods. You should also add createTable()/dropTable() methods for convenience.
This is more complicated. You could:
Send your own email about selected shop address.
Search the controller method which send the email you wish to change.
Then you should override that method by copying the file to your module, delete all the other methods and
rename the class definition inside -> class AdminAddressesController extends AdminAddressesControllerCore
There should be an array of email placeholders and their values, which the controllers assigns.
for example '{order_id}'. You should add your email variable to array {chosen_shop_info} and assign whole
paragraph of text to it. Then you may use it in the actual email template which you can edit in BO.
This is more or less the only way I know to edit the existing templates, because you can't do conditional statements inside email templates.
To add chosen address to order page in BO, you should use another hook - hookDisplayAdminOrder.
here you can add your own block to be display in order summary.
To find out which hooks are available, go to Hook.php and look for method exec(). Add this line error_log($hook_name).
When you perform a specific action, executed hooks will be logged and you will see what kind of hook you need.

How do I load a Sitecore sublayout automatically so that permissions are respected?

I've created a sublayout (usercontrol) with some simple html. I want to display this sublayout only if the user belongs to a certain role.
If I use the built in sitecore developer center to add the sublayout, I end up with something like
<sc:Sublayout runat="server"
RenderingID="{item guid here}"
Path="/layouts/sublayouts/someusercontrol.ascx"
ID="Sublayout1" placeholder="content"></sc:Sublayout>
Denying read permission for the sublayout used there has no affect (I assume it's getting loaded because the file path is there right? ). If I take the Path out I get nothing regardless of current user role.
I don't want to manually check if the current user is in the right role from the codebehind. What markup do I use to get the sublayout to consider the user's permissions and determine visibility?
I don't think it's possible to control sublayout visibility based on a user role in markup. If you dynamically added this sublayout to a placeholder, you could use conditional rendering ("Personalize" button in 6.5) to accomplish this, hiding the component unless the user is a member of a specific role.

yii access control filter rules in controllers

When writing rules for access control in yii controllers, possible parameters to be set
for a rule are 'action' - sets to which action the rule applies; 'users', 'roles', etc.
Now, both the yii guide (pdf) and reference (I have chm file) say that it's possible to set,
also, a controller id for the controller the rule should apply to.
Now, if we are already putting these rules in a controller class/file, how would we be able
to put some other controller (other than the current one) as the parameter here, meaning
how would some other controller whose id we mention here - how would it know there is a rule that applies to it, since it's written in a completely other controller class/file?
How would the controller be aware of a rule that mentions it, if it's written outside of it,
in a completely different controller?
You can hook into CWebApplication::beforeControllerAction() to apply filters before the controller even gets the request.
~thinkt4nk
One case where you could use this is if you set some rules in a base controller and extend it. Maybe you have some admin-only controllers, then you can save a little code by just adding these rules into a base Controller that all other controllers extend?
Also, this might be used if you are attaching Behaviors to the controller?
I've never used this rule though, I'm just hypothesizing. :)
Dear Friend,
Yii give us 3 type of user groups
(*)- for All(guest),
(#)- for registered,
(admin)- for super user we can use it from Controller / public function accessRules()
add if you wanna custom user rights than u can also use
1)ttp://www.yiiframework.com/extension/yii-user-management/
and u can also use "Yii-Rights" which is best for customization
2)http://www.yiiframework.com/forum/index.php?/topic/10556-extension-rights/page_p_51869#entry51869
Regard,
Bhavik Chauhan