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

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.

Related

Changing default dropdown value in sap crm web ui

I want to change default values which gets populated in the below picture.
I tried modifying get_v_role method but it didn't serve my purpose.
Please help.
In personalize->personalize settings, there is sort option. It sometimes overwrites this arrangement of values of get_v method.
Also code can be written in inbound plug of this view. I did it for overview page drop down and it worked. You can try for your search page.
For filtering/changing drop-down value of search parameter, You've to Re-define GET_DQUERY_DEFINITIONS method of ZCL_XXX_IMPL class of component. GET_V_XX methods are only used to modify drop-down/F4 help of view pages not the search view.
STEPS:
Click F2 while placing the cursor on Account ID(for which parameter you want
to modify) drop-down.
Go to BSP Component using t-code - BSP_WD_CMPWB
Enter the component name and Enhancement set
Select the view.
Go to Implementation class .
If your component is enhanced then it will be having ZCL_XXX_IMPL class. otherwise you've to enhance that component. Click on that class.
After that find GET_DQUERY_DEFINITIONS method and implement same way as
GET_V_XXX.

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.

Inherit form view from a predefined module

I want to create my own module which is an extension of sale.order. I want to have a form view which is like sale order view with few additional fields,
My problem is that when I inherit the sale order view and add say three extra fields these fields comes by default in the Original Sale Order form view too.
is this the default behaviour or am I doing something wrong ?
What should I do to achieve what I want.
If you inherit the view and add some fields using 'xpath' , than it will change the original view by installing your new module. This is the application of view inheritance. If you want to keep the original form view as it is after the installation of your module and want to define another which have some extra fields only for your customized module, you have to make a different form view without inheriting the original one. May be in future , there will be a facility of extending an existing form view, but right now you can't do that.
I think you need to check view_id in your code may be a view_id is common so you are updating a default view of sale order.
When you are inherit one view of sale order a functionality will be added in a form not whole view will be generated.
Still this is not solution send me your code i will review it.

Add Control after Items in GridView Group

I'm currently developing a Windows 8 Store app that uses a Grouped GridView in the HubPage showing Highlights for some Categories. So far, when clicking the Header you see More Highlights for this Category.
Now i want to add a control at the end of every Group leading the User to the "non-highlight" Category site, where just all the Items of this category are displayed.
Is there an easy and elegant way to do this - propably with a Template is suppose.
( i think the latest Bing-News-App has a similar feature )
Thanks in advance for every help.
There are a couple of ways you can do this.
You can add an arbitrary object to the end of your group, then use a DataTemplateSelector to style it.
You can create your own VariableSizedWrapGrid with the control added to the end in the constructor (slash "Arrange"). You can then add an arbitrary click handler as a dependency property and only show the button if the click handler is set, so you can reuse this on other pages, etc.
You can change the GroupStyle to include something similar at the end of the group, but it likely won't animate with the other items in the group (if that's important to you).
The easiest one to do is probably the first one. If your group is a list of SampleItems then make a subclass of the SampleItem class called something similar to TerminalSampleItem. Create a template for it (like you've made other data templates). Make an ItemTemplateSelector that has two properties, NonTerminalDataTemplate and TerminalDataTemplate (assuming you only have two data templates). Have the SelectTemplateOverride function check for (item is TerminalSampleItem);

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.