From 92309d3968c543ba109cacf8599410c95371d3fb Mon Sep 17 00:00:00 2001 From: Jared Esparza Date: Tue, 5 Jul 2022 12:12:00 +0200 Subject: [PATCH] Modify get_parcel to get the parcel of the current crop and Add check if all the plantations has a parcel in the current crop | #059962 --- locale/ca.po | 8 ++++++++ locale/es.po | 8 ++++++++ message.xml | 3 +++ weighing.py | 19 ++++++++++++++++++- 4 files changed, 37 insertions(+), 1 deletion(-) diff --git a/locale/ca.po b/locale/ca.po index 264eabe..8e2d9ff 100644 --- a/locale/ca.po +++ b/locale/ca.po @@ -1544,6 +1544,14 @@ msgstr "" "El pes en \"%(weighing)s\" no està totalment distibuit i no s'ha forçat " "l'anàlisi" +msgctxt "model:ir.message,text:msg_parcel_without_current_crop" +msgid "" +"The plantation \"%(plantation)s\" in the weighing \"%(weighing)s\" has no " +"parcel of the weighing's crop." +msgstr "" +"La plantació \"%(plantation)s\" en la pesada \"%(weighing)s\" no te una " +"parcel·la amb la collita de la pesada" + msgctxt "model:ir.message,text:msg_uom_not_fit" msgid "" "Inputs from Production template \"%(production)s\" must be of uom " diff --git a/locale/es.po b/locale/es.po index 981d356..2c62a45 100644 --- a/locale/es.po +++ b/locale/es.po @@ -1545,6 +1545,14 @@ msgstr "" "El peso en \"%(weighin)s\" no está totalmente distribuido i no se ha forzado" " el anàlisis" +msgctxt "model:ir.message,text:msg_parcel_without_current_crop" +msgid "" +"The plantation \"%(plantation)s\" in the weighing \"%(weighing)s\" has no " +"parcel of the weighing's crop." +msgstr "" +"La plantación \"%(plantation)s\" en la pesada \"%(weighing)s\" no tiene una " +"parcela con la cosecha de la pesada" + msgctxt "model:ir.message,text:msg_uom_not_fit" msgid "" "Inputs from Production template \"%(production)s\" must be of uom " diff --git a/message.xml b/message.xml index 69771d1..e005b29 100644 --- a/message.xml +++ b/message.xml @@ -45,5 +45,8 @@ this repository contains the full copyright notices and license terms. --> The weighing center "%(center)s" dont have a to location configured. + + The plantation "%(plantation)s" in the weighing "%(weighing)s" has no parcel of the weighing's crop. + diff --git a/weighing.py b/weighing.py index 0129578..4957fed 100644 --- a/weighing.py +++ b/weighing.py @@ -206,12 +206,18 @@ class Weighing(Workflow, ModelSQL, ModelView): return crop[0].id def get_parcel(self): + crop = self.on_change_with_crop() if not self.plantations: return plantation = self.plantations[0].plantation if not plantation or not plantation.parcels: return - return plantation.parcels[0] + res = None + for parcel in plantation.parcels: + if parcel.crop.id == crop: + res = parcel + break + return res @fields.depends('plantations') def on_change_with_variety(self): @@ -529,6 +535,17 @@ class Weighing(Workflow, ModelSQL, ModelView): Beneficiary.delete([x for x in weighing.beneficiaries]) parcel = weighing.get_parcel() + + # Check if all plantations has a parcel in the weighing's crop + for plantation in weighing.plantations: + plantation = plantation.plantation + for parcel in plantation.parcels: + if parcel.crop == weighing.crop: + break + else: + raise UserError(gettext('agronomics.msg_parcel_without_current_crop', + weighing=weighing.rec_name, plantation=plantation.code)) + if not parcel: continue