From 280b359a0349e140008b64f347bad386be67f1ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=80ngel=20=C3=80lvarez?= Date: Tue, 15 Nov 2022 17:16:26 +0100 Subject: [PATCH] fix some bugs --- contract.py | 2 +- plot.py | 2 +- weighing.py | 3 +++ 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/contract.py b/contract.py index 31eeaba..2e8afc0 100644 --- a/contract.py +++ b/contract.py @@ -89,7 +89,7 @@ class AgronomicsContract(Workflow, ModelSQL, ModelView): return 'draft' def get_rec_name(self, name): - ret = self.producer.rec_name + ret = self.producer and self.producer.rec_name or '' if self.start_date: ret += ' - %s' % (self.start_date) return ret diff --git a/plot.py b/plot.py index 70635f7..13957eb 100644 --- a/plot.py +++ b/plot.py @@ -143,7 +143,7 @@ class Parcel(ModelSQL, ModelView): )*self.surface, 2) def get_purchased_quantity(self, name): - return sum([w.netweight for w in self.weighings if not w.table]) + return sum([w.netweight for w in self.weighings if not w.table and w.netweight]) def get_remaining_quantity(self, name): return (self.max_production or 0) - (self.purchased_quantity or 0) diff --git a/weighing.py b/weighing.py index 4957fed..549241f 100644 --- a/weighing.py +++ b/weighing.py @@ -355,6 +355,7 @@ class Weighing(Workflow, ModelSQL, ModelView): WeighingParcel = pool.get('agronomics.weighing-agronomics.parcel') weighing_parcel_to_save = [] to_analysis = [] + for weighing in weighings: if not weighing.table: if weighing.parcels: @@ -380,8 +381,10 @@ class Weighing(Workflow, ModelSQL, ModelView): else: remaining_weight -= parcel.remaining_quantity weighing_parcel.netweight = parcel.remaining_quantity + if weighing_parcel.netweight: weighing_parcel_to_save.append(weighing_parcel) + if remaining_weight == 0: to_analysis.append(weighing) else: