This question has been flagged
1 Reply
3264 Views

I am trying to implement the following code in order to create a function field in my product model that will give me the qty_available result less the outgoing_qty result. I am currently getting a: 'NoneType' object has no attribute 'qty_available' error. I am assuming that is because I am trying to get the value of qty_available in the incorrect way. What adjustments should I make to my code?

from openerp.osv import fields, osv

class real_inventory_counter(osv.osv):
    _inherit = "product.product"
    
    def real_inventory_count(self, cr, uid, arg, ids, field_name, context=None):
        result = {}
        for product in self.browse(cr, uid, ids, context):
            result[product.id] = product.qty_available - product.outgoing_qty
        return result

    
    _columns = {
        'testing_time': fields.integer('Test Field', help='Just a field for testing'),
        'real_inventory_count': fields.function(real_inventory_count, type='float', string='Real Inventory Count'),
    } 

Avatar
Discard
Best Answer

There already is a module that does that: stock_available_immediately

Avatar
Discard