This forum is now just an archive. Use the new Q&A website
It is currently Thu Apr 24, 2014 3:34 pm

All times are UTC + 2 hours




Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Stock: Number of Packages per Line
PostPosted: Sun Sep 23, 2012 9:19 am 
Offline

Joined: Wed Jun 27, 2012 1:51 pm
Posts: 22
I'm sure this is very easy, but I just can't seem to get it done. How to calculate the amount of packages need for a product_line?! Intended formula (in stock.move): line.product_qty / line.product_id.packaging[0].qty.

My code:
Code:
class stock_picking_lines_number_packages(osv.osv):
    _inherit = 'stock.move'

    def _number_packages(self, cr, uid, ids, name, args, context=None):
        res = []
        for line in pick.move_lines:
           res[line.id] = line.product_qty/line.product_id.packaging[0].qty   
        return res


    _columns = {
        'number_packages': fields.function(_number_packages, type='integer', string='Number Packages', store = True),
        }
stock_picking_lines_number_packages()


Possibly above is correct (not sure, though), but if so:
1. Why can't I then call 'line.number_packages' for my report?
2. Why remains the database column 'number_packages' empty.

Thank you for your kind help!

P.S. I am a rookie, so a somewhat detailed explanation would definitely help.


Top
 Profile  
 
 Post subject: Re: Stock: Number of Packages per Line
PostPosted: Thu Dec 06, 2012 11:26 pm 
Offline

Joined: Wed Dec 22, 2010 10:54 am
Posts: 474
hi

you should do a research on the subject


Code:
pack_obj=self.pool.get('product.packaging')   
        res = {}
        for line in self.browse(cr, uid, ids, context=context):
             res[line.id] = 0
             if line.product_id:
               pack_id = pack_obj.search(cr, uid, [('product_id','=',line.product_id.id)])[0]
               colis= pack_obj.browse(cr,uid,pack_id).qty
                         
               res[line.id]= int(line.product_uos_qty / colis ) or 0             
               return res


but this method has a problem if you do not package related.
pack_id = pack_obj.search(cr, uid, [('product_id','=',line.product_id.id)])[0]

if you make pack_id = pack_obj.search(cr, uid, [('product_id','=',line.product_id.id)])[0] or fale,
or condition : if pacj_id :
in the MRP i have problème.

someone has an idea ?

_________________
je fume du thé et je reste éveillé le cauchemar continue


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC + 2 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:

Protected by Anti-Spam ACP