Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

1

function.field store help

By
Erhuvwu Akpobaro
on 4/6/15, 6:20 PM 808 views

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 ?

Erhuvwu Akpobaro
on 4/7/15, 2:54 AM

I modify your code, but you will have again an error because your request finish with : INNER JOIN accoun$ ????

Cyril Gaspard (GEM)
on 4/7/15, 2:41 PM

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) )

Erhuvwu Akpobaro
on 4/8/15, 3:32 AM

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

Cyril Gaspard (GEM)
on 4/8/15, 5:51 PM
1

Cyril Gaspard (GEM)

--Cyril Gaspard (GEM)--
4136
| 5 6 8
Paris, France
--Cyril Gaspard (GEM)--

Forum contributor since 2008

Cyril Gaspard (GEM)
On 4/6/15, 7:24 PM

remove :

_defaults = {

'invoice_company':_get_invoice_company ,

}

what do you want to do exactly with your field invoice_company, your code is very strange ...

1
Erhuvwu Akpobaro
On 4/7/15, 2:55 AM

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 upvote for you, you have now enough karma to upvote, edit previous post ..., bye

Cyril Gaspard (GEM)
on 4/8/15, 6:42 PM

Do you how to edit the point of sale module/interface ?

Erhuvwu Akpobaro
on 4/12/15, 4:27 PM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 4/6/15, 6:20 PM
Seen: 808 times
Last updated: 4/8/15, 6:40 PM