adding total weight in lots

This commit is contained in:
Cayo Puigdefabregas 2021-09-10 14:07:35 +02:00
parent b7396b4f23
commit bcaf907255
2 changed files with 10 additions and 1 deletions

View File

@ -133,7 +133,15 @@ class TradeDocument(Thing):
@property @property
def total_weight(self): def total_weight(self):
"""Return all weight than this container have.""" """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): def _warning_actions(self, actions):
"""Show warning actions""" """Show warning actions"""

View File

@ -30,3 +30,4 @@ class TradeDocument(Thing):
lot = NestedOn('Lot', only_query='id', description=m.TradeDocument.lot.__doc__) lot = NestedOn('Lot', only_query='id', description=m.TradeDocument.lot.__doc__)
trading = SanitizedStr(dump_only=True, description='') trading = SanitizedStr(dump_only=True, description='')
weight = Float(required=False, description=m.TradeDocument.weight.comment) weight = Float(required=False, description=m.TradeDocument.weight.comment)
total_weight = Float(required=False, description=m.TradeDocument.weight.comment)