I'm very new in python, I'm trying to pool products id from sale order line in odoo, but I did not get any output in log file. I need help.
class SOL(models.Model):
_inherit = 'sale.order.line'
def _get_sale_o_line(self, cr, uid, ids, context=None):
so_pool = self.pool.get('sale.order.line')
for so_obj in so_pool.search(cr, uid, ids,context=None):
logging.debug('Order Name: %s' so_obj.order_id)
obj=SOL()
obj._get_sale_o_line()
You can't call methods like that in Odoo. That class is part of an ORM.
Documentation
Related
In the Odoo 9 source code the class ir_attachment has the following comment:
The 'data' function field (_data_get,data_set) is implemented using
_file_read, _file_write and _file_delete which can be overridden to
implement other storage engines, such methods should check for other
location pseudo uri (example: hdfs://hadoppserver)
It tells me I can over ride the read, write and delete methods, but I have not been able to find any documentation on how to do so.
I tried overriding like I would other Odoo modules by creating an module with this code:
class Attachments(osv.osv):
_inherit = 'ir.attachment'
def _file_read(self, cr, uid, fname, bin_size=False):
r = super(Attachments, self)._file_read(cr, uid, fname, bin_size)
return r
def _file_write(self, cr, uid, value, checksum):
name = super(Attachments, self)._filewrite(self, cr, uid, value, checksum):
return fname
However, I set several breakpoints and it appears Odoo is not registering these function overrides. Is there a different way to override methods in runtime directory?
See this github project for a complete and working example: https://github.com/tvanesse/odoo-s3
i have problems with understanding the inheritance in odoo.
Consider following code in module 1
`class pos_order(models.Model):
_inherit = 'pos.order'
def create_from_ui(self, cr, uid, orders, context=None):
super(models.Model, self).create_from_ui(cr, uid, orders, context=context)
print "1"`
and same in module 2, only it prints 2. First module 1 is installed then module 2. As you see in both the pos_order is extended with custom create_from_ui function. If create_from_ui is called now module2 order is called which in turn calls module1 order which in turn calls original. How could I call only the original now (lets say i dont want "1" printed under certain circumstances)?
Cheers and big thanks for all the help
Odoo sets up the hierarchy, but then the normal Python rules apply.
If you want to call the original method from module 2, you can import that specific class from the original module, being careful to pass self to it, as you're calling the method from the class, not an instance:
from openerp.addons.point_of_sale.point_of_sale import pos_order as original_pos_order
class pos_order(models.Model):
_inherit = 'pos.order'
def create_from_ui(self, cr, uid, orders, context=None):
original_pos_order.create_from_ui(self, cr, uid, orders, context=context)
print "1"`
I am working on odoo v8 and I am trying to modify the access rights view in users form. I want to modify the form so that when I select a role for each module's category it will call the onchange method and update the checkboxes below (Technical Settings, Usability and Other). Currently changes made will only appear after I saved the form. But I want to make it update onfly for administrator to verify before saving into the database. But it seems when I return a dict from the onchange method the system is not aware the existence of the field (eg virtual fields like in_group_1, in_group_2 etc). Is there anyway to do this?
#api.v7
def check_acl(self, cr, uid, ids, my_field, context=None):
return {'value': {'in_group_1': True}}
You can check is administrator or not by this function
def check_user(self, uid=None):
if uid is None:
uid = request.uid
is_admin = request.registry['res.users']._is_admin(request.cr, uid, [uid])
if not is_admin:
raise openerp.exceptions.AccessError("Only administrators can upload a module")
and call this function with arguments like:
uid = request.session.authenticate(request.db, login, password)
self.check_user(uid)
and you can use this function in your onchange
#api.v7
def check_acl(self, cr, uid, ids, my_field, context=None):
if self.check_user(uid):
return {'value': {'in_group_1': True}}
I am going to write a method in point of sale containing existing .py files. Should I create new python file ? or write new method in existing .py files??
If you need to add a new method to a particular model (e.g. sale.order), then inherit that particular model and add your method in a separate module i.e. custom module.
class SaleOrder(models.Model):
_inherit='sale.order'
#api.multi
def custom_test_method(self...)
Note:
This is in order to migrate to new version or update your code from github. Mostly, any modification to your model needs to be done in a custom module only.
Never change the code in the base module or the module's not written by you. Because when transition to update the latest code in order to get new functionalities or migration to another version, there is a plenty of chances for code loss and results to weird behaviour.
Use custom module for new method or overwriting the existing method
Eg: To add new method in pos module's, model "pos.order":
class pos_order(orm.Model):
_inherit = "pos.order"
def your_new_method(self, cr, uid, ids, args, context=None):
## your code
return
For existing method:
class pos_order(orm.Model):
_inherit = "pos.order"
def your_existing_method(self, cr, uid, ids, args, context=None):
res = super(pos_order, self).your_existing_method(cr, uid, ids, args, context=context)
## your code to change the existing method result
return res
I need to get all objects from a class and iterate through them.
I tried this, but without any results:
def my_method(self, cr, uid, ids, context=None):
pool_obj = pooler.get_pool(cr.dbname)
my_objects=pool_obj.get('project.myobject')
#here i'll iterate through them...
How can I get in 'my_objects' variable all objects of class 'project.myobject'?
You have to search with empty parameters to get all the ids of existing objects, like:
myobj = pool.get('project.myobject')
ids = myobj.search(cr, uid, [])
Then you can browse or read them passing an id or the list of ids.
It seems you forget to import pooler.
from openerp import pooler
May it will help you.