changeset 0f40f0f40eb2 in modules/product_kit:default
details:
https://hg.tryton.org/modules/product_kit?cmd=changeset&node=0f40f0f40eb2
description:
Use Function fields to compute moves
Using the Function field on stock move as relation field is not very
efficient
because of the sub-query it generates.
issue11204
review395421008
diffstat:
common.py | 18 ++++++++++++++++++
purchase.py | 15 ++++++++++++---
sale.py | 15 ++++++++++++---
tests/scenario_product_kit_sale.rst | 2 ++
4 files changed, 44 insertions(+), 6 deletions(-)
diffs (104 lines):
diff -r a9bc9a58f16c -r 0f40f0f40eb2 common.py
--- a/common.py Sun Jan 30 13:14:44 2022 +0100
+++ b/common.py Sun Mar 06 18:13:01 2022 +0100
@@ -51,6 +51,24 @@
return _search_shipments_returns
+def get_moves(func):
+ @wraps(func)
+ def wrapper(self, name):
+ return func(self, name) + [
+ m.id for l in self.lines for c in l.components for m in c.moves]
+ return wrapper
+
+
+def search_moves(func):
+ @wraps(func)
+ def wrapper(cls, name, clause):
+ return ['OR',
+ func(cls, name, clause),
+ ('lines.components.' + clause[0],) + tuple(clause[1:]),
+ ]
+ return wrapper
+
+
def order_mixin(prefix):
class OrderMixin(ModelStorage):
diff -r a9bc9a58f16c -r 0f40f0f40eb2 purchase.py
--- a/purchase.py Sun Jan 30 13:14:44 2022 +0100
+++ b/purchase.py Sun Mar 06 18:13:01 2022 +0100
@@ -6,9 +6,9 @@
from trytond.pool import Pool, PoolMeta
from .common import (
- AmendmentLineMixin, get_shipments_returns, handle_shipment_exception_mixin,
- order_line_component_mixin, order_line_mixin, order_mixin,
- search_shipments_returns)
+ AmendmentLineMixin, get_moves, get_shipments_returns,
+ handle_shipment_exception_mixin, order_line_component_mixin,
+ order_line_mixin, order_mixin, search_moves, search_shipments_returns)
from .product import ComponentMixin
@@ -43,6 +43,15 @@
def search_shipment_returns(cls, name, clause):
return super().search_shipments(name, clause)
+ @get_moves
+ def get_moves(self, name):
+ return super().get_moves(name)
+
+ @classmethod
+ @search_moves
+ def search_moves(cls, name, clause):
+ return super().search_moves(name, clause)
+
class Line(order_line_mixin('purchase'), metaclass=PoolMeta):
__name__ = 'purchase.line'
diff -r a9bc9a58f16c -r 0f40f0f40eb2 sale.py
--- a/sale.py Sun Jan 30 13:14:44 2022 +0100
+++ b/sale.py Sun Mar 06 18:13:01 2022 +0100
@@ -6,9 +6,9 @@
from trytond.pool import Pool, PoolMeta
from .common import (
- AmendmentLineMixin, get_shipments_returns, handle_shipment_exception_mixin,
- order_line_component_mixin, order_line_mixin, order_mixin,
- search_shipments_returns)
+ AmendmentLineMixin, get_moves, get_shipments_returns,
+ handle_shipment_exception_mixin, order_line_component_mixin,
+ order_line_mixin, order_mixin, search_moves, search_shipments_returns)
from .product import ComponentMixin
@@ -43,6 +43,15 @@
def search_shipment_returns(cls, name, clause):
return super().search_shipments(name, clause)
+ @get_moves
+ def get_moves(self, name):
+ return super().get_moves(name)
+
+ @classmethod
+ @search_moves
+ def search_moves(cls, name, clause):
+ return super().search_moves(name, clause)
+
class Line(order_line_mixin('sale'), metaclass=PoolMeta):
__name__ = 'sale.line'
diff -r a9bc9a58f16c -r 0f40f0f40eb2 tests/scenario_product_kit_sale.rst
--- a/tests/scenario_product_kit_sale.rst Sun Jan 30 13:14:44 2022 +0100
+++ b/tests/scenario_product_kit_sale.rst Sun Mar 06 18:13:01 2022 +0100
@@ -187,6 +187,8 @@
>>> shipment, = sale.shipments
>>> len(shipment.outgoing_moves)
4
+ >>> len(sale.moves)
+ 4
>>> product2quantity = {
... m.product: m.quantity for m in shipment.outgoing_moves}
>>> product2quantity[composed_product]