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.

0

Fields Function: Not Displaying the answer. Please Need Help(SOLVED)

By
Alcaline
on 10/12/14, 9:04 PM 1,400 views

I made this code to compute the total quantity of the product but the answer is displaying in the view. how can i fix this?? any help please.. Stock.picking.out class...

Here's my code:

 def _get_total_quantity(self, cr, uid, ids, field_name, args, context=None):
        
        res ={}
        product_qty = {}
        total_quantity= {}
        qty = 0.00
    
        move_pool = self.pool.get('stock.move')

        for stock_move_picking in self.browse(cr,uid,ids,context=context):
            total_qty = move_pool.search(cr,uid,[('picking_id','=', stock_move_picking.id)],context = context)
            for picking in move_pool.browse(cr,uid,total_qty, context=context):
           qty = qty + picking.product_qty
            res[stock_move_picking.id] = {'total_quantity':qty}
        return res
    
    _columns = {
               'total_quantity':fields.function(_get_total_quantity, type='float', method=True,store=True, multi=True, string='Summation of Quantity', ),            
                 }
    
   

2
Piyush Suva
On 10/14/14, 1:35 AM

I think its due to store= True.

because store=True means it will take value from database.

And In database it will store when you create/Update in existing record.

First try without  store = True

But If you want forcefully store value in database then you should try below.

def _get_stock_move_picking_id( cr, uid, ids, context=None):

        ### logic to return id list of parent object.

def _get_total_quantity(self, cr, uid, ids, field_name, args, context=None):

          #Same logic what ever you done 

         res[stock_move_picking.id] = qty

return res               

'total_quantity':fields.function(total_quantity, method=True,string='tOtal Amount',

                                  store={
                                               'YOUR_LINE_OBJECT': (_get_stock_move_picking_id, ['product_qty'], 20),
                                              }),

 

thanks Piyush but it didn't work:(

Alcaline
on 10/14/14, 1:45 AM
1
Nirav Jani
On 10/14/14, 5:41 AM

Hello ,

your "total_quantity" field also put in stock.picking and check it.

 

thanks Nirav Jani finally it works.

Alcaline
on 10/14/14, 9:22 PM
0
Anand Patel
On 10/13/14, 3:03 AM

Hi,

Please try this one

res[ids[0]] = qty

return res

got the same error too AttributeError: 'float' object has no attribute 'iteritems'

Alcaline
on 10/13/14, 3:27 AM
0
Vee
On 10/12/14, 11:43 PM

Hi Alcaline,

I find this works for me. v7/v8/v9

import logging

_logger = logging.getLogger('WHATEVER U WANT')

_logger = logging.getLogger(__name__) ## Or FileName of your py.file

_logger.info("Testing: {0}{1}{2}".format(item1, item2, item3))

Now, Im not sure about all your other code, see doc's and check your

Def function & feilds.function are correct.

And test test test... Let us know how you go, & Good luck. 

thanks Vee

Alcaline
on 10/14/14, 1:31 AM
0

Ben Bernard

--Ben Bernard--
1083
| 4 3 6
Jakarta, Indonesia
--Ben Bernard--
Ben Bernard
On 10/13/14, 12:04 AM

You define a function field with type float. So, change the following line

res[stock_move_picking.id] = {'total_quantity':qty}

to this one.

res[stock_move_picking.id] = qty

hi Ben I tried that one but it gives me an Error like this AttributeError: 'float' object has no attribute 'iteritems'. how to solve this one??

Alcaline
on 10/13/14, 1:10 AM

Try to set multi=False, in function field definition. I assume no other field is depend on the function.

Ben Bernard
on 10/13/14, 3:56 AM

there's no error occurred but still it doe not display the value of my answer.. i don't know what the problem.. thanks Ben

Alcaline
on 10/13/14, 4:51 AM

Hi, I see you update your post. While debugging, what is the value of qty?

Ben Bernard
on 10/14/14, 1:14 AM

the value of qty is the summation of Quantity/RSQ. I used this equation to call the value of qty and view to field 'total_quantity' res[stock_move_picking.id] = {'total_quantity':qty} Did i used the wrong equation or what?

Alcaline
on 10/14/14, 1:29 AM

Just wondering. It's hard to read other's code in limited context and awful format (provided by this forum).

Ben Bernard
on 10/14/14, 2:18 AM

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: 10/12/14, 9:04 PM
Seen: 1400 times
Last updated: 3/16/15, 8:10 AM