Hey guys ,
I have field.function that shows the right value i want however when i try to display this value in the point of sake(through my own customization) nothing shows , i believe this is because my field.function is not stored :
class cm_product_template(osv.osv):
_name = 'product.template'
_inherit = "product.template"
def _get_invoice_company(self, cr, uid, ids, field, parameter, context=None):
#def _get_invoice_company(self, cr, uid, ids , context=None):
context = context or {}
invoice = {}
#period_obj3 = self.pool.get('product.template')
for auto1 in self.browse(cr, uid, ids, context=context):
prod_temp_id = auto1.id
print prod_temp_id
# cr.execute("SELECT id FROM pp_feature WHERE plan = %d" %(featurename) )
cr.execute("""SELECT f.name FROM product_template pt INNER JOIN product_product pp on pp.product_tmpl_id = pt.id INNER JOIN account_analytic_invoice_line aal on aal.product_id = pp.id INNER JOIN account_analytic_account aaa on aaa.id = aal.analytic_account_id INNER JOIN res_company f on f.id = aaa.invcompany_id WHERE pp.product_tmpl_id = %s""", % (prod_temp_id,) )
# res = cr.fetchall()
res = cr.fetchone()
print res
invoice.update({prod_temp_id : res and res[0] or False })
return invoice
_columns = {
'cm_property_ids': fields.one2many('cm.property', 'product_template_id', 'Products') ,
'invoice_company':fields.function(_get_invoice_company , type='integer' , store=True, method=True ,string='Invoice Company')
}
# example od function you can use in defaults
def _get_default_invoice_company(self, cr, uid, context=None):
context = context or {}
# do your treatment here
company_id = False
return company_id
_defaults = {
'invoice_company': _get_default_invoice_company ,
}
When i add store=True i get this error :
File "/opt/odoo/odoo/openerp/models.py", line 2399, in _set_default_value_on_column
default = default(self, cr, SUPERUSER_ID, context)
TypeError: _get_invoice_company() takes at least 6 arguments (4 given)
I am confused why i cant store the function value field in the database any ideas to get passed this ?
Hi , the field invoice company is a a new inherited field on the produced template page , I want this field to automatically show a value on on already creates products and new products . thanks for the help on removing the default field however I get this error now : Value Error : expected singleton prod_temp_Id = auto.id Is the function trying to store multiple values ?
I modify your code, but you will have again an error because your request finish with : INNER JOIN accoun$ ????
My aplogies the right sql query is : cr.execute("SELECT f.name FROM product_template pt INNER JOIN product_product pp on pp.product_tmpl_id = pt.id INNER JOIN account_analytic_invoice_line aal on aal.product_id = pp.id inner join account_analytic_account aaa on aaa.id = aal.analytic_account_id inner join res_company f on f.id = aaa.invcompany_id WHERE pp.product_tmpl_id = %d" %(prod_temp_id) )
I update your function, should work, for use of a function in _defaults, I gave you an example of function to call, see function _get_default_invoice_company which is the only prototype of function you can use in this case (in body function, you can't use ids), bye