def _get_location_change(self, cr, uid, ids, context=None):
return self.pool.get('stock.inventory.line').search(cr, uid, [('location_id', 'in', ids)], context=context)
-
+
+ def _get_prodlot_change(self, cr, uid, ids, context=None):
+ return self.pool.get('stock.inventory.line').search(cr, uid, [('prod_lot_id', 'in', ids)], context=context)
+
_columns = {
'inventory_id': fields.many2one('stock.inventory', 'Inventory', ondelete='cascade', select=True),
- 'location_id': fields.many2one('stock.location', 'Location', required=True),
+ 'location_id': fields.many2one('stock.location', 'Location', required=True, select=True),
'product_id': fields.many2one('product.product', 'Product', required=True, select=True),
- 'product_uom': fields.many2one('product.uom', 'Product Unit of Measure', required=True),
- 'product_qty': fields.float('Quantity', digits_compute=dp.get_precision('Product Unit of Measure')),
- 'company_id': fields.related('inventory_id','company_id',type='many2one',relation='res.company',string='Company',store=True, select=True, readonly=True),
+ 'package_id': fields.many2one('stock.quant.package', 'Pack', select=True),
+ 'product_uom_id': fields.many2one('product.uom', 'Product Unit of Measure', required=True),
+ 'product_qty': fields.float('Checked Quantity', digits_compute=dp.get_precision('Product Unit of Measure')),
+ 'company_id': fields.related('inventory_id', 'company_id', type='many2one', relation='res.company', string='Company', store=True, select=True, readonly=True),
'prod_lot_id': fields.many2one('stock.production.lot', 'Serial Number', domain="[('product_id','=',product_id)]"),
- 'state': fields.related('inventory_id','state',type='char',string='Status',readonly=True),
+ 'state': fields.related('inventory_id', 'state', type='char', string='Status', readonly=True),
+ 'th_qty': fields.float('Theoretical Quantity', readonly=True),
+ 'partner_id': fields.many2one('res.partner', 'Owner'),
'product_name': fields.related('product_id', 'name', type='char', string='Product name', store={
'product.product': (_get_product_name_change, ['name', 'default_code'], 20),
'stock.inventory.line': (lambda self, cr, uid, ids, c={}: ids, ['product_id'], 20),}),
'location_name': fields.related('location_id', 'complete_name', type='char', string='Location name', store={
'stock.location': (_get_location_change, ['name', 'location_id', 'active'], 20),
'stock.inventory.line': (lambda self, cr, uid, ids, c={}: ids, ['location_id'], 20),}),
+ 'prodlot_name': fields.related('prod_lot_id', 'name', type='char', string='Serial Number name', store={
+ 'stock.production.lot': (_get_prodlot_change, ['name'], 20),
+ 'stock.inventory.line': (lambda self, cr, uid, ids, c={}: ids, ['prod_lot_id'], 20),}),
}
- def _default_stock_location(self, cr, uid, context=None):
- stock_location = self.pool.get('ir.model.data').get_object(cr, uid, 'stock', 'stock_location_stock')
- return stock_location.id
-
_defaults = {
- 'location_id': _default_stock_location
+ 'product_qty': 1,
}
- def on_change_product_id(self, cr, uid, ids, location_id, product, uom=False, to_date=False):
+ def _resolve_inventory_line(self, cr, uid, inventory_line, theorical_lines, context=None):
+ #TODO : package_id management !
+ found = False
+ uom_obj = self.pool.get('product.uom')
+ for th_line in theorical_lines:
+ #We try to match the inventory line with a theorical line with same product, lot, location and owner
+ if th_line['location_id'] == inventory_line.location_id.id and th_line['product_id'] == inventory_line.product_id.id and th_line['prod_lot_id'] == inventory_line.prod_lot_id.id and th_line['partner_id'] == inventory_line.partner_id.id:
+ uom_reference = inventory_line.product_id.uom_id
+ real_qty = uom_obj._compute_qty_obj(cr, uid, inventory_line.product_uom_id, inventory_line.product_qty, uom_reference)
+ th_line['product_qty'] -= real_qty
+ found = True
+ break
+ #if it was still not found, we add it to the theorical lines so that it will create a stock move for it
+ if not found:
+ vals = {
+ 'inventory_id': inventory_line.inventory_id.id,
+ 'location_id': inventory_line.location_id.id,
+ 'product_id': inventory_line.product_id.id,
+ 'product_uom_id': inventory_line.product_id.uom_id.id,
+ 'product_qty': -inventory_line.product_qty,
+ 'prod_lot_id': inventory_line.prod_lot_id.id,
+ 'partner_id': inventory_line.partner_id.id,
+ }
+ theorical_lines.append(vals)
+
+ def on_change_product_id(self, cr, uid, ids, location_id, product, uom=False, owner_id=False, lot_id=False, package_id=False, context=None):
""" Changes UoM and name if product_id changes.
@param location_id: Location id
@param product: Changed product_id