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)