[IMP] when stock becomes negative no product update

bzr revid: jco@openerp.com-20130510083509-ym9ddc2g024rlkos
This commit is contained in:
Josse Colpaert
2013-05-10 10:35:09 +02:00
parent 119414447e
commit b9ab99af8a
2 changed files with 20 additions and 10 deletions
+15 -6
View File
@@ -1629,13 +1629,13 @@ class stock_move(osv.osv):
if (record.state=='done') and (record.location_dest_id.usage == 'view' ):
raise osv.except_osv(_('Error'), _('You cannot move product %s to a location of type view %s.')% (record.product_id.name, record.location_dest_id.name))
return True
#TODO: change demo data for this to be possible
def _check_company_location(self, cr, uid, ids, context=None):
for record in self.browse(cr, uid, ids, context=context):
if record.location_id.company_id and (record.company_id.id != record.location_id.company_id.id):
raise osv.except_osv(_('Error'), _('The company of the source location %s and the company of the stock move should be the same') % record.location_id.name)
if record.location_dest_id.company_id and (record.company_id.id != record.location_dest_id.company_id.id):
raise osv.except_osv(_('Error'), _('The company of the destination location %s and the company of the stock move should be the same') % record.location_dest_id.name)
# for record in self.browse(cr, uid, ids, context=context):
# if record.location_id.company_id and (record.company_id.id != record.location_id.company_id.id):
# raise osv.except_osv(_('Error'), _('The company of the source location %s and the company of the stock move should be the same') % record.location_id.name)
# if record.location_dest_id.company_id and (record.company_id.id != record.location_dest_id.company_id.id):
# raise osv.except_osv(_('Error'), _('The company of the destination location %s and the company of the stock move should be the same') % record.location_dest_id.name)
return True
_constraints = [
@@ -2381,6 +2381,15 @@ class stock_move(osv.osv):
if move.move_dest_id.auto_validate:
self.action_done(cr, uid, [move.move_dest_id.id], context=context)
#TODO: Create stock move matchings if still necessary
match_obj = self.pool.get("stock.move.matching")
matches = match_obj.search(cr, uid, [("move_out_id", "=", move.id)], context = context)
if not matches:
fifo = not (move.product_id.cost_method == 'lifo')
#matchings = self.pool.get("product.product').get_stock_matchings_fifolifo(cr, uid, [move.product_id.id], move.product_qty, fifo, move.uom_id.id, False)
#for match in matchings:
self._create_product_valuation_moves(cr, uid, move, context=context)
if move.state not in ('confirmed','done','assigned'):
todo.append(move.id)
+5 -4
View File
@@ -168,8 +168,8 @@ class stock_move(osv.osv):
if product.qty_available >= product_uom_qty:
self.write(cr, uid, move.id, {'price_unit': price_amount / amount}, context=context)
else:
self.write(cr, uid, move.id, {'price_unit': price_amount / amount}, context=context)
standard_price = product.standard_price
self.write(cr, uid, move.id, {'price_unit': standard_price}, context=context)
#convert price, no need of UoM conversion as it is the total price
currency_id = move.company_id.currency_id.id
@@ -179,8 +179,9 @@ class stock_move(osv.osv):
price_amount)
else:
new_price = price_amount
#new_price does not depend on qty as it is the total amount => no conversion needed for uom
product_obj.write(cr, uid, product.id, {'standard_price': new_price / product_uom_qty}, context=ctx)
if product.qty_available >= product_uom_qty:
product_obj.write(cr, uid, product.id, {'standard_price': new_price / product_uom_qty}, context=ctx)
# When the move is products returned to supplier or return products from customer,
# it should be treated as a normal in or out, so for every in
elif cost_method in ['fifo', 'lifo']: