mirror of
https://github.com/NaN-tic/trytond-patches.git
synced 2023-12-14 06:03:03 +01:00
90 lines
3.8 KiB
Diff
90 lines
3.8 KiB
Diff
|
diff -r e9a7f9fd73aa stock.py
|
||
|
--- a/trytond/trytond/modules/stock_lot/stock.py Wed Jun 17 11:46:34 2015 +0200
|
||
|
+++ b/trytond/trytond/modules/stock_lot/stock.py Wed Jun 17 11:47:43 2015 +0200
|
||
|
@@ -1,7 +1,6 @@
|
||
|
#This file is part of Tryton. The COPYRIGHT file at the top level of
|
||
|
#this repository contains the full copyright notices and license terms.
|
||
|
import datetime
|
||
|
-from collections import defaultdict
|
||
|
|
||
|
from trytond.model import ModelView, ModelSQL, Workflow, fields
|
||
|
from trytond.pyson import PYSONEncoder, Eval
|
||
|
@@ -200,64 +199,8 @@
|
||
|
__name__ = 'stock.inventory'
|
||
|
|
||
|
@classmethod
|
||
|
- def complete_lines(cls, inventories):
|
||
|
- pool = Pool()
|
||
|
- Product = pool.get('product.product')
|
||
|
- Line = pool.get('stock.inventory.line')
|
||
|
-
|
||
|
- super(Inventory, cls).complete_lines(inventories)
|
||
|
-
|
||
|
- # Create and/or update lines with product that will require lot for
|
||
|
- # their moves.
|
||
|
- to_create = []
|
||
|
- for inventory in inventories:
|
||
|
- product2lines = defaultdict(list)
|
||
|
- for line in inventory.lines:
|
||
|
- if (line.product.lot_is_required(inventory.location,
|
||
|
- inventory.lost_found)
|
||
|
- or line.product.lot_is_required(inventory.lost_found,
|
||
|
- inventory.location)):
|
||
|
- product2lines[line.product.id].append(line)
|
||
|
- if product2lines:
|
||
|
- with Transaction().set_context(stock_date_end=inventory.date):
|
||
|
- pbl = Product.products_by_location([inventory.location.id],
|
||
|
- product_ids=product2lines.keys(),
|
||
|
- grouping=('product', 'lot'))
|
||
|
- product_qty = defaultdict(dict)
|
||
|
- for (location_id, product_id, lot_id), quantity \
|
||
|
- in pbl.iteritems():
|
||
|
- product_qty[product_id][lot_id] = quantity
|
||
|
-
|
||
|
- products = Product.browse(product_qty.keys())
|
||
|
- product2uom = dict((p.id, p.default_uom.id) for p in products)
|
||
|
-
|
||
|
- for product_id, lines in product2lines.iteritems():
|
||
|
- quantities = product_qty[product_id]
|
||
|
- uom_id = product2uom[product_id]
|
||
|
- for line in lines:
|
||
|
- lot_id = line.lot.id if line.lot else None
|
||
|
- if lot_id in quantities:
|
||
|
- quantity = quantities.pop(lot_id)
|
||
|
- elif lot_id is None and quantities:
|
||
|
- lot_id = quantities.keys()[0]
|
||
|
- quantity = quantities.pop(lot_id)
|
||
|
- else:
|
||
|
- lot_id = None
|
||
|
- quantity = 0.0
|
||
|
-
|
||
|
- values = line.update_values4complete(quantity, uom_id)
|
||
|
- if (values or lot_id != (line.lot.id
|
||
|
- if line.lot else None)):
|
||
|
- values['lot'] = lot_id
|
||
|
- Line.write([line], values)
|
||
|
- if quantities:
|
||
|
- for lot_id, quantity in quantities.iteritems():
|
||
|
- values = Line.create_values4complete(product_id,
|
||
|
- inventory, quantity, uom_id)
|
||
|
- values['lot'] = lot_id
|
||
|
- to_create.append(values)
|
||
|
- if to_create:
|
||
|
- Line.create(to_create)
|
||
|
+ def grouping(cls):
|
||
|
+ return super(Inventory, cls).grouping() + ('lot', )
|
||
|
|
||
|
|
||
|
class InventoryLine:
|
||
|
@@ -279,10 +222,6 @@
|
||
|
rec_name += ' - %s' % self.lot.rec_name
|
||
|
return rec_name
|
||
|
|
||
|
- @property
|
||
|
- def unique_key(self):
|
||
|
- return super(InventoryLine, self).unique_key + (self.lot,)
|
||
|
-
|
||
|
def get_move(self):
|
||
|
move = super(InventoryLine, self).get_move()
|
||
|
if move:
|