How to call method of the installed module into another installed module in Odoo 11? - odoo-11

I am using Odoo 11 and I want to use a method of
Sale module > models > sale > SaleOrder > action_confirm method
into
Mail module > models > mail_mail > MailMail > send method
How to use the method of a module to another module method?

The method of a module that you are describing is just a method will be part of an Odoo model, sale.order in this case so if you wanna call it you just need a sale.order record to call the method. For example:
order_id = 3
order = self.env['sale.order'].browse(order_id)
order.action_confirm()
You could use that code anywhere you wanna use it. Normally in an Odoo method that provides the self.env access to the Odoo models.

Related

Laravel Gate resource with policy not existing

I am trying to implement Policies in my project and I have a custom method askFriend that I want to add to my UserRelationPolicy.
So I implemented in my UserRelationPolicy the askFriend method but when trying to call it from the UserRelationPolicy#askFriend I asked myself how to call it from this method.
Something like $this->authorize('askFriend', $friend); but it was not working, kind of ignoring it at all. So I searched further in the documentation and found that I could bind with a Gate method the specific method in the UserRelationPolicy to a resource name like this :
Gate::resource('userrelation', 'UserRelationPolicy', [
'userrelation.askfriendrelation' => 'askFriendRelation'
]);
You can find the representation here : Documentation Writing Gate
When I try to execute this code I get the following error :
Call to undefined method Illuminate\Auth\Access\Gate::resource()
And nothing more. The Resource method doesn't seem to exist at all. After many search, trying to include every Gate in the header. Trying to call it staticly or with an instance. Nothing work and the method is nowhere near to be found...
Is it something forgotten ? How can I call a custom method from a controller in a policy class ?
Are you sure you are using 5.4? The method Gate::resource was implemented only in 5.4.
If you are using any version behind you will have to use the Gate::define.
Set the Gate abilities in the App\Providers\AuthServiceProvider like this:
Gate::define('userrelation.askfriendrelation', 'UserRelationPolicy#askFriend');

Django autocomplete Light in list filters for admin

I have successfully setup the Autocomplete Registry and have my django admin forms where if you go to the form, the auto completes works. I would like to be able to extend the autocompletes to work on the list_filter view as well. So when you are looking at the view generated by Admin.py -- that the list_filter inputs that are generated would also use the autocomplete jquery + service URL.
I didn't see anything listed in the documentation, anyone have any pointers?
If you are using Django version greater then 2.0, you can try using the built-in autocomplete fields for this purpose.
By default, the admin uses a select-box interface () for those fields. Sometimes you don’t want to incur the overhead of selecting all the related instances to display in the dropdown.
The Select2 input looks similar to the default input but comes with a search feature that loads the options asynchronously
There is a simple app which does this:
To install use: pip install django-admin-autocomplete-filter
Then add admin_auto_filters to your INSTALLED_APPS inside settings.py of your project.
Let's say we have following models:
class Artist(models.Model):
name = models.CharField(max_length=128)
class Album(models.Model):
name = models.CharField(max_length=64)
artist = models.ForeignKey(Artist, on_delete=models.CASCADE)
cover = models.CharField(max_length=256, null=True, default=None)
And you would like to filter results in Album Admin on the basis of artist, then you can define search fields in Artist and then define filter as:
from admin_auto_filters.filters import AutocompleteFilter
class ArtistFilter(AutocompleteFilter):
title = 'Artist' # display title
field_name = 'artist' # name of the foreign key field
class ArtistAdmin(admin.ModelAdmin):
search_fields = ['name'] # this is required for django's autocomplete functionality
...
class AlbumAdmin(admin.ModelAdmin):
list_filter = [ArtistFilter]
'''
defining this class is required for AutocompleteFilter
it's a bug and I am working on it.
'''
class Media:
pass
After following these steps you may see the filter as:
You should define your own admin filter that inherits from django.contrib.admin.SimpleListFilter. Then should provide your own HTML template for this filter which will use one of django-autocomplete-light widgets. As a parameter for widget you should define required autocomplete URL. And do not forget to include proper JS and CSS for it.
All of this is done in special app for this: dal-admin-filters

Joomla 2.5 getUserStateFromRequest load error

I was following the example to implement custom filters in Joomla 2.5 admin component.
But I am getting error at models populateState method:
Call to undefined method
somecompModelsomecomp::getUserStateFromRequest().
$app = JFactory::getApplication('administrator');
// Load the filter state.
$search = $this->getUserStateFromRequest($this->context.'.filter.search', 'filter_search');
Error disappears if I call getUserStateFromRequest using $app:
$app->getUserStateFromRequest($this->context.'.filter.search', 'filter_search');
So whats the problem? In default Joomla components I've seen that it use the same approach and it works. Maybe I miss something in my model class?
Any ideas?
This is happened because $app is an object of your application class. As you defined it in your code.
$app = JFactory::getApplication('administrator');
and getUserStateFromRequest method is defind in that Application class.so you have to use it like this if you want to access this method.
$app->getUserStateFromRequest($this->context.'.filter.search', 'filter_search');
And for your information $this variable is your local object.

Getting virtuemart price at the template

I'm new in joomla and I'm getting crazy because as I wanna get the price (and another metadata) of a product at the template just using the ID of the product, does anyboy could tell me how getting it, perhaps with a helper o static method or instanciating a class? (I have googled it). It's Virtuemart 1.1.3 and joomla 1.5.10.
Thanks in advance.
Still not clear on where you're wanting to use it, but if it's from within VM that you want to get the product information, there are a number of places you can look at and see if it suits what you're trying to accomplish:
Virtuemart Custom Theme.php
Found at components\com_virtuemart\themes\default\theme.php. Allows you to write custom functions to access anything in VM for your own use.
/**
* This is the theme's function file.
* It allows you to declare additional functions and classes
* that may be used in your templates
*
Browse Results on Flypage
The search/browse saves many product fields - they're saved into an array near the end of html\show.browse.php (look for $products[$i]['product_price'] = $product_price;) , then loaded into the VM templates with $tpl->set( 'products', $products ) , and finally, used when rendering the product fly page

get magento module config data in Observer

I created a module with an observer for the sales module with event hook ‘sales_order_shipment_save_after’ ,
My module has the following files
Company/Modulename/etc/config.xml
Company/Modulename/etc/system.xml
Company/Modulename/Model/Observer.php
there are four fields in the modules admin configuration fields
I want to get those saved data in the Observer class.
using $this->getConfigData(’password’); gives a
Call to undefined method
error
Any suggestions?
Magento uses a static method on the global Mage application object to get configuration values
$config = Mage::getStoreConfig('section_name/group/field'); //value
$config = Mage::getStoreConfig('section_name/group'); //array
An amendment to Alan's completely correct answer.
Along with path as first parameter, getStoreConfig also accepts storeid as second parameter(optional).
Well, this is useful when you want to retrieve store-wise values.
Alan has mentioned this point in his own tutorial. I guess, he has not mentioned here just because OP has not mentioned this requirement in his question.
Please refer this
In a shipment module I can use $this->getConfigData for fields in system.xml, but in another kind of modules sometimes not, e.g. extends Mage_Core_Model_Abstract, than I must use getStoreConfig. So the answer is you don't have to use always getStoreConfig. But I don't know why ...
Answer: getConfigData is just defined in a shipment class and uses getStoreConfig too. A little confusing that some functions are extra defined and unneeded in fact ...

Resources