From bcaf907255b808f611cbbdff423554a5d683ba0c Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Fri, 10 Sep 2021 14:07:35 +0200 Subject: [PATCH] adding total weight in lots --- ereuse_devicehub/resources/tradedocument/models.py | 10 +++++++++- ereuse_devicehub/resources/tradedocument/schemas.py | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/ereuse_devicehub/resources/tradedocument/models.py b/ereuse_devicehub/resources/tradedocument/models.py index 28f4a8cf..36ae370a 100644 --- a/ereuse_devicehub/resources/tradedocument/models.py +++ b/ereuse_devicehub/resources/tradedocument/models.py @@ -133,7 +133,15 @@ class TradeDocument(Thing): @property def total_weight(self): """Return all weight than this container have.""" - return sum([x.weight for x in self.actions if x.type == 'MoveOnDocument']) + self.weight + weight = self.weight or 0 + for x in self.actions: + if not x.type == 'MoveOnDocument' or not x.weight: + continue + if self == x.container_from: + continue + weight += x.weight + + return weight def _warning_actions(self, actions): """Show warning actions""" diff --git a/ereuse_devicehub/resources/tradedocument/schemas.py b/ereuse_devicehub/resources/tradedocument/schemas.py index cfa74637..99aa9ab6 100644 --- a/ereuse_devicehub/resources/tradedocument/schemas.py +++ b/ereuse_devicehub/resources/tradedocument/schemas.py @@ -30,3 +30,4 @@ class TradeDocument(Thing): lot = NestedOn('Lot', only_query='id', description=m.TradeDocument.lot.__doc__) trading = SanitizedStr(dump_only=True, description='') weight = Float(required=False, description=m.TradeDocument.weight.comment) + total_weight = Float(required=False, description=m.TradeDocument.weight.comment)