Fix non applying patch for stock

This commit is contained in:
Sergi Almacellas Abellana 2014-06-30 14:05:48 +02:00
parent a3a4a9cfe6
commit aafa2ce839
1 changed files with 33 additions and 73 deletions

View File

@ -1,8 +1,6 @@
Index: move.py diff --git a/modules/stock/move.py b/modules/stock/move.py
=================================================================== --- a/modules/stock/move.py
+++ b/modules/stock/move.py
--- ./modules/stock/move.py
+++ ./modules/stock/move.py
@@ -4,12 +4,15 @@ @@ -4,12 +4,15 @@
import operator import operator
from decimal import Decimal from decimal import Decimal
@ -12,7 +10,7 @@ Index: move.py
+from sql.aggregate import Sum +from sql.aggregate import Sum
+from sql.conditionals import Coalesce +from sql.conditionals import Coalesce
from sql.operators import Concat from sql.operators import Concat
from trytond.model import Workflow, Model, ModelView, ModelSQL, fields from trytond.model import Workflow, Model, ModelView, ModelSQL, fields
from trytond import backend from trytond import backend
-from trytond.pyson import In, Eval, Not, Equal, If, Get, Bool -from trytond.pyson import In, Eval, Not, Equal, If, Get, Bool
@ -20,11 +18,11 @@ Index: move.py
+from trytond.tools import reduce_ids +from trytond.tools import reduce_ids
from trytond.transaction import Transaction from trytond.transaction import Transaction
from trytond.pool import Pool from trytond.pool import Pool
@@ -88,6 +91,10 @@ @@ -88,6 +91,10 @@
Compute the domain to filter records which validates the domain over Compute the domain to filter records which validates the domain over
quantity field. quantity field.
+ The context with keys: + The context with keys:
+ stock_skip_warehouse: if set, quantities on a warehouse are no more + stock_skip_warehouse: if set, quantities on a warehouse are no more
+ quantities of all child locations but quantities of the storage + quantities of all child locations but quantities of the storage
@ -39,10 +37,10 @@ Index: move.py
- Product = pool.get('product.product') - Product = pool.get('product.product')
+ Location = pool.get('stock.location') + Location = pool.get('stock.location')
+ Move = pool.get('stock.move') + Move = pool.get('stock.move')
if not location_ids or not domain: if not location_ids or not domain:
return [] return []
- def _search_quantity_eval_domain(line, domain): - def _search_quantity_eval_domain(line, domain):
- operator_funcs = { - operator_funcs = {
- '=': operator.eq, - '=': operator.eq,
@ -68,7 +66,7 @@ Index: move.py
+ location_ids.remove(location.id) + location_ids.remove(location.id)
+ location_ids.add(location.storage_location.id) + location_ids.add(location.storage_location.id)
+ location_ids = list(location_ids) + location_ids = list(location_ids)
with Transaction().set_context(cls._quantity_context(name)): with Transaction().set_context(cls._quantity_context(name)):
- pbl = Product.products_by_location( - pbl = Product.products_by_location(
- location_ids=location_ids, - location_ids=location_ids,
@ -90,7 +88,7 @@ Index: move.py
+ quantities = Move.compute_quantities(query, location_ids, + quantities = Move.compute_quantities(query, location_ids,
+ with_childs=True, grouping=grouping, + with_childs=True, grouping=grouping,
+ grouping_filter=None) + grouping_filter=None)
- processed_lines = [] - processed_lines = []
- for key, quantity in pbl.iteritems(): - for key, quantity in pbl.iteritems():
+ record_ids = [] + record_ids = []
@ -102,12 +100,12 @@ Index: move.py
- name: quantity, - name: quantity,
- }) - })
+ record_ids.append(key[position]) + record_ids.append(key[position])
- record_ids = [line['record_id'] for line in processed_lines - record_ids = [line['record_id'] for line in processed_lines
- if _search_quantity_eval_domain(line, domain)] - if _search_quantity_eval_domain(line, domain)]
return [('id', 'in', record_ids)] return [('id', 'in', record_ids)]
@@ -789,3 +801,367 @@ @@ -789,3 +801,367 @@
pbl[from_key] = pbl.get(from_key, 0.0) - qty_default_uom pbl[from_key] = pbl.get(from_key, 0.0) - qty_default_uom
pbl[to_key] = pbl.get(to_key, 0.0) + qty_default_uom pbl[to_key] = pbl.get(to_key, 0.0) + qty_default_uom
@ -476,12 +474,9 @@ Index: move.py
+ quantities[key] = Uom.round(quantity, uom.rounding) + quantities[key] = Uom.round(quantity, uom.rounding)
+ +
+ return quantities + return quantities
diff --git a/modules/stock/product.py b/modules/stock/product.py
Index: product.py --- a/modules/stock/product.py
=================================================================== +++ b/modules/stock/product.py
--- ./modules/stock/product.py
+++ ./modules/stock/product.py
@@ -2,9 +2,8 @@ @@ -2,9 +2,8 @@
#this repository contains the full copyright notices and license terms. #this repository contains the full copyright notices and license terms.
import datetime import datetime
@ -493,37 +488,23 @@ Index: product.py
+from sql.aggregate import Max +from sql.aggregate import Max
from sql.functions import Now from sql.functions import Now
from sql.conditionals import Coalesce from sql.conditionals import Coalesce
@@ -12,7 +11,6 @@ @@ -12,7 +11,6 @@
from trytond.wizard import Wizard, StateView, StateAction, Button from trytond.wizard import Wizard, StateView, StateAction, Button
from trytond.pyson import PYSONEncoder, Eval, Or from trytond.pyson import PYSONEncoder, Eval, Or
from trytond.transaction import Transaction from trytond.transaction import Transaction
-from trytond.tools import reduce_ids -from trytond.tools import reduce_ids
from trytond.pool import Pool, PoolMeta from trytond.pool import Pool, PoolMeta
from .move import StockMixin from .move import StockMixin
@@ -122,348 +120,52 @@ @@ -136,322 +134,40 @@
uom of the product. If product_ids is None all products are used.
If with_childs, it computes also for child locations.
The context with keys: grouping defines how stock moves are grouped.
- stock_date_end: if set the date of the stock computation.
- stock_date_start: if set return the delta of the stock
- between the two dates, (ignored if stock_date_end is
- missing).
- stock_assign: if set compute also the assigned moves as done.
- forecast: if set compute the forecast quantity.
- stock_destinations: A list of location ids. If set, restrict
- the computation to moves from and to those locations.
- stock_skip_warehouse: if set, quantities on a warehouse are no
- more quantities of all child locations but quantities of
- the storage zone.
- If product_ids is None all products are used.
- If with_childs, it computes also for child locations.
- grouping defines how stock moves are grouped.
+ stock_skip_warehouse: if set, quantities on a warehouse are no more + stock_skip_warehouse: if set, quantities on a warehouse are no more
+ quantities of all child locations but quantities of the storage + quantities of all child locations but quantities of the storage
+ zone. + zone.
Return a dictionary with location id and grouping as key Return a dictionary with location id and grouping as key
and quantity as value. and quantity as value.
""" """
@ -552,7 +533,7 @@ Index: product.py
- if field not in Move._fields: - if field not in Move._fields:
- raise ValueError('"%s" has no field "%s"' % (Move, field)) - raise ValueError('"%s" has no field "%s"' % (Move, field))
- assert 'product' in grouping - assert 'product' in grouping
# Skip warehouse location in favor of their storage location # Skip warehouse location in favor of their storage location
# to compute quantities. Keep track of which ids to remove # to compute quantities. Keep track of which ids to remove
# and to add after the query. # and to add after the query.
@ -578,7 +559,7 @@ Index: product.py
+ location_ids.add(location.storage_location.id) + location_ids.add(location.storage_location.id)
+ wh_to_add[location.id] = location.storage_location.id + wh_to_add[location.id] = location.storage_location.id
+ location_ids = list(location_ids) + location_ids = list(location_ids)
- move_rule_query = Rule.domain_get('stock.move') - move_rule_query = Rule.domain_get('stock.move')
- if move_rule_query is None: - if move_rule_query is None:
- move_rule_query = Literal(True) - move_rule_query = Literal(True)
@ -854,38 +835,18 @@ Index: product.py
+ grouping=grouping, grouping_filter=grouping_filter) + grouping=grouping, grouping_filter=grouping_filter)
+ if query is None: + if query is None:
+ return {} + return {}
+ quantities = Move.compute_quantities(query, location_ids, with_childs, + res = Move.compute_quantities(query, location_ids, with_childs,
+ grouping=grouping, grouping_filter=grouping_filter) + grouping=grouping, grouping_filter=grouping_filter)
if wh_to_add: if wh_to_add:
if product_ids is None:
product_ids = set((p for s, p in res))
for wh, storage in wh_to_add.iteritems(): for wh, storage in wh_to_add.iteritems():
for product in product_ids: diff --git a/modules/stock/tests/test_stock.py b/modules/stock/tests/test_stock.py
- if (storage, product) in res: --- a/modules/stock/tests/test_stock.py
- res[(wh, product)] = res[(storage, product)] +++ b/modules/stock/tests/test_stock.py
+ if (storage, product) in quantities:
+ quantities[(wh, product)] = quantities[
+ (storage, product)]
if storage in storage_to_remove:
- del res[(storage, product)]
-
- return res
+ del quantities[(storage, product)]
+ return quantities
class ProductByLocationStart(ModelView):
Index: tests/test_stock.py
===================================================================
--- ./modules/stock/tests/test_stock.py
+++ ./modules/stock/tests/test_stock.py
@@ -280,6 +280,68 @@ @@ -280,6 +280,68 @@
else: else:
self.assertEqual(product_reloaded.quantity, quantity) self.assertEqual(product_reloaded.quantity, quantity)
+ # Python 2.6 compatibility (assertIn and assertNotIn added in 2.7) + # Python 2.6 compatibility (assertIn and assertNotIn added in 2.7)
+ assertIn = getattr(self, 'assertIn', + assertIn = getattr(self, 'assertIn',
+ lambda a, b: self.assertTrue(a in b)) + lambda a, b: self.assertTrue(a in b))
@ -956,7 +917,6 @@ Index: tests/test_stock.py
{(storage.id, product.id): quantity}) {(storage.id, product.id): quantity})
tests_product_quantity(context, quantity) tests_product_quantity(context, quantity)
+ tests_product_search_quantity(context, quantity) + tests_product_search_quantity(context, quantity)
test_products_by_location() test_products_by_location()