mirror of
https://github.com/NaN-tic/trytond-agronomics.git
synced 2023-12-14 05:33:01 +01:00
Add parcel weighing control | #044369
This commit is contained in:
parent
0b3999e996
commit
c08f5c1b4f
|
@ -38,6 +38,7 @@ def register():
|
|||
weighing.Weighing,
|
||||
weighing.WeighingPlantation,
|
||||
weighing.WeighingDo,
|
||||
weighing.WeighingParcel,
|
||||
quality.Configuration,
|
||||
quality.ConfigurationCompany,
|
||||
quality.ProductQualitySample,
|
||||
|
|
78
locale/ca.po
78
locale/ca.po
|
@ -126,6 +126,10 @@ msgctxt "field:agronomics.parcel,beneficiaries:"
|
|||
msgid "Beneficiaries"
|
||||
msgstr "Beneficiaris"
|
||||
|
||||
msgctxt "field:agronomics.parcel,purchased_quantity:"
|
||||
msgid "Bought Quantity"
|
||||
msgstr "Quantitat comprada"
|
||||
|
||||
msgctxt "field:agronomics.parcel,crop:"
|
||||
msgid "Crop"
|
||||
msgstr "Collita"
|
||||
|
@ -164,7 +168,11 @@ msgstr "Productor"
|
|||
|
||||
msgctxt "field:agronomics.parcel,product:"
|
||||
msgid "Product"
|
||||
msgstr "Productes"
|
||||
msgstr "Producte"
|
||||
|
||||
msgctxt "field:agronomics.parcel,remaining_quantity:"
|
||||
msgid "Remainig Quantity"
|
||||
msgstr "Quantitat restant"
|
||||
|
||||
msgctxt "field:agronomics.parcel,species:"
|
||||
msgid "Spices"
|
||||
|
@ -186,6 +194,10 @@ msgctxt "field:agronomics.parcel,variety:"
|
|||
msgid "Variety"
|
||||
msgstr "Varietat"
|
||||
|
||||
msgctxt "field:agronomics.parcel,weighings:"
|
||||
msgid "Weighings"
|
||||
msgstr "Pesades"
|
||||
|
||||
msgctxt "field:agronomics.parcel-agronomics.do,do:"
|
||||
msgid "Denomination Origin"
|
||||
msgstr "Denominació d'origen"
|
||||
|
@ -230,14 +242,26 @@ msgctxt "field:agronomics.weighing,ecological:"
|
|||
msgid "Ecological"
|
||||
msgstr "Ecològic"
|
||||
|
||||
msgctxt "field:agronomics.weighing,forced_analysis:"
|
||||
msgid "Forced Analysis"
|
||||
msgstr "Anàlisi forçat"
|
||||
|
||||
msgctxt "field:agronomics.weighing,netweight:"
|
||||
msgid "Net Weight"
|
||||
msgstr "Pes net"
|
||||
|
||||
msgctxt "field:agronomics.weighing,not_assigned_weight:"
|
||||
msgid "Not Assigned Weight"
|
||||
msgstr "Pes no assignat"
|
||||
|
||||
msgctxt "field:agronomics.weighing,number:"
|
||||
msgid "Number"
|
||||
msgstr "Número"
|
||||
|
||||
msgctxt "field:agronomics.weighing,parcels:"
|
||||
msgid "Parcels"
|
||||
msgstr "Parcel·les"
|
||||
|
||||
msgctxt "field:agronomics.weighing,plantations:"
|
||||
msgid "plantations"
|
||||
msgstr "Plantacions"
|
||||
|
@ -294,9 +318,29 @@ msgctxt "field:agronomics.weighing-agronomics.do,weighing:"
|
|||
msgid "Weighing"
|
||||
msgstr "Pesada"
|
||||
|
||||
msgctxt "field:agronomics.weighing-agronomics.parcel,netweight:"
|
||||
msgid "Net Weight"
|
||||
msgstr "Pes net"
|
||||
|
||||
msgctxt "field:agronomics.weighing-agronomics.parcel,parcel:"
|
||||
msgid "Parcel"
|
||||
msgstr "Parcel·la"
|
||||
|
||||
msgctxt "field:agronomics.weighing-agronomics.parcel,table:"
|
||||
msgid "Table"
|
||||
msgstr "Taula"
|
||||
|
||||
msgctxt "field:agronomics.weighing-agronomics.parcel,weighing:"
|
||||
msgid "Weighing"
|
||||
msgstr "Pesada"
|
||||
|
||||
msgctxt "field:agronomics.weighing-agronomics.plantation,party:"
|
||||
msgid "Party"
|
||||
msgstr "Tercer"
|
||||
|
||||
msgctxt "field:agronomics.weighing-agronomics.plantation,plantation:"
|
||||
msgid "Plantation"
|
||||
msgstr "Plantacións"
|
||||
msgstr "Plantacions"
|
||||
|
||||
msgctxt "field:agronomics.weighing-agronomics.plantation,weighing:"
|
||||
msgid "Weighing"
|
||||
|
@ -1115,6 +1159,10 @@ msgctxt "model:agronomics.weighing-agronomics.do,name:"
|
|||
msgid "Weighing - Denomination Origin"
|
||||
msgstr "Pesada - Denominació Origen"
|
||||
|
||||
msgctxt "model:agronomics.weighing-agronomics.parcel,name:"
|
||||
msgid "Weighing-Parcel"
|
||||
msgstr "Pesada-Parcel·la"
|
||||
|
||||
msgctxt "model:agronomics.weighing-agronomics.plantation,name:"
|
||||
msgid "Weighing - Plantations"
|
||||
msgstr "Pesada - Plantacions"
|
||||
|
@ -1288,6 +1336,12 @@ msgstr ""
|
|||
"No es pot finalitzar el moviment perquè la unitat de mesura del moviment no "
|
||||
"coincideix amb la unitat de mesura de la capacitat de la ubicació destí."
|
||||
|
||||
msgctxt "model:ir.message,text:msg_not_assigned_weight"
|
||||
msgid ""
|
||||
"The weight in \"%(weighing)s\" is not distributed and its not being forced to analysis"
|
||||
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_uom_not_fit"
|
||||
msgid ""
|
||||
"Inputs from Production template \"%(production)s\" must be of uom "
|
||||
|
@ -1317,14 +1371,14 @@ msgctxt ""
|
|||
msgid "Done"
|
||||
msgstr "Realitzar"
|
||||
|
||||
msgctxt "model:ir.model.button,string:weighing_analysis_button"
|
||||
msgid "Analysis"
|
||||
msgstr "Anàlisi"
|
||||
|
||||
msgctxt "model:ir.model.button,string:weighing_cancel_button"
|
||||
msgid "Cancel"
|
||||
msgstr "Cancel·lat"
|
||||
|
||||
msgctxt "model:ir.model.button,string:weighing_distribute_button"
|
||||
msgid "Analysis"
|
||||
msgstr "Anàlisi"
|
||||
|
||||
msgctxt "model:ir.model.button,string:weighing_done_button"
|
||||
msgid "Done"
|
||||
msgstr "Realitzat"
|
||||
|
@ -1333,6 +1387,10 @@ msgctxt "model:ir.model.button,string:weighing_draft_button"
|
|||
msgid "Draft"
|
||||
msgstr "Esborrany"
|
||||
|
||||
msgctxt "model:ir.model.button,string:weighing_force_analysis_button"
|
||||
msgid "Force Analysis"
|
||||
msgstr "Forçar anàlisi"
|
||||
|
||||
msgctxt "model:ir.model.button,string:weighing_process_button"
|
||||
msgid "Process"
|
||||
msgstr "Processa"
|
||||
|
@ -1674,6 +1732,10 @@ msgctxt "selection:agronomics.weighing,state:"
|
|||
msgid "Cancelled"
|
||||
msgstr "Cancel·lat"
|
||||
|
||||
msgctxt "selection:agronomics.weighing,state:"
|
||||
msgid "Distributed"
|
||||
msgstr "Distribuït"
|
||||
|
||||
msgctxt "selection:agronomics.weighing,state:"
|
||||
msgid "Done"
|
||||
msgstr "Realitzat"
|
||||
|
@ -1794,6 +1856,10 @@ msgctxt "selection:production.output.distribution,production_state:"
|
|||
msgid "Waiting"
|
||||
msgstr "En espera"
|
||||
|
||||
msgctxt "view:agronomics.weighing:"
|
||||
msgid "Parcel Distribution"
|
||||
msgstr "Distribució per parcel·les"
|
||||
|
||||
msgctxt "view:product.product:"
|
||||
msgid "Agronomics"
|
||||
msgstr "Agronomics"
|
||||
|
|
78
locale/es.po
78
locale/es.po
|
@ -126,6 +126,10 @@ msgctxt "field:agronomics.parcel,beneficiaries:"
|
|||
msgid "Beneficiaries"
|
||||
msgstr "Beneficiarios"
|
||||
|
||||
msgctxt "field:agronomics.parcel,purchased_quantity:"
|
||||
msgid "Bought Quantity"
|
||||
msgstr "Cantidad comprada"
|
||||
|
||||
msgctxt "field:agronomics.parcel,crop:"
|
||||
msgid "Crop"
|
||||
msgstr "Cosecha"
|
||||
|
@ -164,7 +168,11 @@ msgstr "Productor"
|
|||
|
||||
msgctxt "field:agronomics.parcel,product:"
|
||||
msgid "Product"
|
||||
msgstr "Productos"
|
||||
msgstr "Producto"
|
||||
|
||||
msgctxt "field:agronomics.parcel,remaining_quantity:"
|
||||
msgid "Remainig Quantity"
|
||||
msgstr "Cantidad restante"
|
||||
|
||||
msgctxt "field:agronomics.parcel,species:"
|
||||
msgid "Spices"
|
||||
|
@ -186,6 +194,10 @@ msgctxt "field:agronomics.parcel,variety:"
|
|||
msgid "Variety"
|
||||
msgstr "Variedad"
|
||||
|
||||
msgctxt "field:agronomics.parcel,weighings:"
|
||||
msgid "Weighings"
|
||||
msgstr "Pesadas"
|
||||
|
||||
msgctxt "field:agronomics.parcel-agronomics.do,do:"
|
||||
msgid "Denomination Origin"
|
||||
msgstr "Denominación de origen"
|
||||
|
@ -230,14 +242,26 @@ msgctxt "field:agronomics.weighing,ecological:"
|
|||
msgid "Ecological"
|
||||
msgstr "Ecológico"
|
||||
|
||||
msgctxt "field:agronomics.weighing,forced_analysis:"
|
||||
msgid "Forced Analysis"
|
||||
msgstr "Forzar análisis"
|
||||
|
||||
msgctxt "field:agronomics.weighing,netweight:"
|
||||
msgid "Net Weight"
|
||||
msgstr "Peso neto"
|
||||
|
||||
msgctxt "field:agronomics.weighing,not_assigned_weight:"
|
||||
msgid "Not Assigned Weight"
|
||||
msgstr "Peso no asignado"
|
||||
|
||||
msgctxt "field:agronomics.weighing,number:"
|
||||
msgid "Number"
|
||||
msgstr "Número"
|
||||
|
||||
msgctxt "field:agronomics.weighing,parcels:"
|
||||
msgid "Parcels"
|
||||
msgstr "Parcelas"
|
||||
|
||||
msgctxt "field:agronomics.weighing,plantations:"
|
||||
msgid "plantations"
|
||||
msgstr "Plantación"
|
||||
|
@ -294,9 +318,29 @@ msgctxt "field:agronomics.weighing-agronomics.do,weighing:"
|
|||
msgid "Weighing"
|
||||
msgstr "Pesada"
|
||||
|
||||
msgctxt "field:agronomics.weighing-agronomics.parcel,netweight:"
|
||||
msgid "Net Weight"
|
||||
msgstr "Peso neto"
|
||||
|
||||
msgctxt "field:agronomics.weighing-agronomics.parcel,parcel:"
|
||||
msgid "Parcel"
|
||||
msgstr "Parcela"
|
||||
|
||||
msgctxt "field:agronomics.weighing-agronomics.parcel,table:"
|
||||
msgid "Table"
|
||||
msgstr "Mesa"
|
||||
|
||||
msgctxt "field:agronomics.weighing-agronomics.parcel,weighing:"
|
||||
msgid "Weighing"
|
||||
msgstr "Pesada"
|
||||
|
||||
msgctxt "field:agronomics.weighing-agronomics.plantation,party:"
|
||||
msgid "Party"
|
||||
msgstr "Tercero"
|
||||
|
||||
msgctxt "field:agronomics.weighing-agronomics.plantation,plantation:"
|
||||
msgid "Plantation"
|
||||
msgstr "Plantaciónes"
|
||||
msgstr "Plantaciones"
|
||||
|
||||
msgctxt "field:agronomics.weighing-agronomics.plantation,weighing:"
|
||||
msgid "Weighing"
|
||||
|
@ -1115,6 +1159,10 @@ msgctxt "model:agronomics.weighing-agronomics.do,name:"
|
|||
msgid "Weighing - Denomination Origin"
|
||||
msgstr "Pesada - Denominación de origen"
|
||||
|
||||
msgctxt "model:agronomics.weighing-agronomics.parcel,name:"
|
||||
msgid "Weighing-Parcel"
|
||||
msgstr "Pesada - Parcela"
|
||||
|
||||
msgctxt "model:agronomics.weighing-agronomics.plantation,name:"
|
||||
msgid "Weighing - Plantations"
|
||||
msgstr "Pesada - Plantación"
|
||||
|
@ -1290,6 +1338,12 @@ msgstr ""
|
|||
"movimiento no coincide con la unidad de medida de capacidad de la de la "
|
||||
"ubicación destino."
|
||||
|
||||
msgctxt "model:ir.message,text:msg_not_assigned_weight"
|
||||
msgid ""
|
||||
"The weight in \"%(weighin)s\" is not distributed and its not being forced to analysis"
|
||||
msgstr ""
|
||||
"El peso en \"%(weighin)s\" no está totalmente distribuido i no se ha forzado el anàlisis"
|
||||
|
||||
msgctxt "model:ir.message,text:msg_uom_not_fit"
|
||||
msgid ""
|
||||
"Inputs from Production template \"%(production)s\" must be of uom "
|
||||
|
@ -1319,14 +1373,14 @@ msgctxt ""
|
|||
msgid "Done"
|
||||
msgstr "Realizar"
|
||||
|
||||
msgctxt "model:ir.model.button,string:weighing_analysis_button"
|
||||
msgid "Analysis"
|
||||
msgstr "Análisis"
|
||||
|
||||
msgctxt "model:ir.model.button,string:weighing_cancel_button"
|
||||
msgid "Cancel"
|
||||
msgstr "Cancel·lar"
|
||||
|
||||
msgctxt "model:ir.model.button,string:weighing_distribute_button"
|
||||
msgid "Analysis"
|
||||
msgstr "Análisis"
|
||||
|
||||
msgctxt "model:ir.model.button,string:weighing_done_button"
|
||||
msgid "Done"
|
||||
msgstr "Realizado"
|
||||
|
@ -1335,6 +1389,10 @@ msgctxt "model:ir.model.button,string:weighing_draft_button"
|
|||
msgid "Draft"
|
||||
msgstr "Esborany"
|
||||
|
||||
msgctxt "model:ir.model.button,string:weighing_force_analysis_button"
|
||||
msgid "Force Analysis"
|
||||
msgstr "Forzar análisis"
|
||||
|
||||
msgctxt "model:ir.model.button,string:weighing_process_button"
|
||||
msgid "Process"
|
||||
msgstr "Procesar"
|
||||
|
@ -1676,6 +1734,10 @@ msgctxt "selection:agronomics.weighing,state:"
|
|||
msgid "Cancelled"
|
||||
msgstr "Cancelado"
|
||||
|
||||
msgctxt "selection:agronomics.weighing,state:"
|
||||
msgid "Distributed"
|
||||
msgstr "Distribuido"
|
||||
|
||||
msgctxt "selection:agronomics.weighing,state:"
|
||||
msgid "Done"
|
||||
msgstr "Realizado"
|
||||
|
@ -1796,6 +1858,10 @@ msgctxt "selection:production.output.distribution,production_state:"
|
|||
msgid "Waiting"
|
||||
msgstr "En espera"
|
||||
|
||||
msgctxt "view:agronomics.weighing:"
|
||||
msgid "Parcel Distribution"
|
||||
msgstr "Distribución por parcelas"
|
||||
|
||||
msgctxt "view:product.product:"
|
||||
msgid "Agronomics"
|
||||
msgstr "Agronomics"
|
||||
|
|
|
@ -36,6 +36,9 @@ this repository contains the full copyright notices and license terms. -->
|
|||
<record model="ir.message" id="msg_move_amount_exceed">
|
||||
<field name="text">The move cannot be done because the amount of the move exceeds the set maximum amount.</field>
|
||||
</record>
|
||||
<record model="ir.message" id="msg_not_assigned_weight">
|
||||
<field name="text">The weight in "%(weighing)s" is not distributed and its not being forced to analysis</field>
|
||||
</record>
|
||||
</data>
|
||||
|
||||
</tryton>
|
||||
|
|
16
plot.py
16
plot.py
|
@ -110,6 +110,16 @@ class Parcel(ModelSQL, ModelView):
|
|||
beneficiaries = fields.One2Many('agronomics.beneficiary', 'parcel',
|
||||
'Beneficiaries')
|
||||
all_do = fields.Function(fields.Char('All DO'), 'get_all_do')
|
||||
weighings = fields.One2Many('agronomics.weighing-agronomics.parcel',
|
||||
'parcel', 'Weighings')
|
||||
purchased_quantity = fields.Function(
|
||||
fields.Float("Bought Quantity", digits=(16, 2)), 'get_purchased_quantity')
|
||||
remaining_quantity = fields.Function(
|
||||
fields.Float("Remainig Quantity", digits=(16, 2)), 'get_remaining_quantity')
|
||||
|
||||
def get_rec_name(self, name):
|
||||
if self.plantation and self.crop:
|
||||
return self.plantation.code + ' - ' + self.crop.rec_name
|
||||
|
||||
@classmethod
|
||||
def validate(cls, records):
|
||||
|
@ -138,6 +148,12 @@ class Parcel(ModelSQL, ModelView):
|
|||
return round(float(min([x.max_production for x in max_production])
|
||||
)*self.surface, 2)
|
||||
|
||||
def get_purchased_quantity(self, name):
|
||||
return sum([w.netweight for w in self.weighings if not w.table])
|
||||
|
||||
def get_remaining_quantity(self, name):
|
||||
return (self.max_production or 0) - (self.purchased_quantity or 0)
|
||||
|
||||
|
||||
class ParcelDo(ModelSQL):
|
||||
"Parcel - Denomination Origin"
|
||||
|
|
|
@ -25,9 +25,14 @@
|
|||
<field name="irrigation"/>
|
||||
<label name="surface"/>
|
||||
<field name="surface"/>
|
||||
<label name="purchased_quantity"/>
|
||||
<field name="purchased_quantity"/>
|
||||
<label name="remaining_quantity"/>
|
||||
<field name="remaining_quantity"/>
|
||||
<newline/>
|
||||
<label name="tenure_regime"/>
|
||||
<field name="tenure_regime" colspan="3"/>
|
||||
<field name="denomination_origin" colspan="4"/>
|
||||
<field name="beneficiaries" colspan="4"/>
|
||||
<field name="weighings" colspan="4"/>
|
||||
</form>
|
||||
|
|
|
@ -10,5 +10,7 @@
|
|||
<field name="premium"/>
|
||||
<field name="producer"/>
|
||||
<field name="max_production"/>
|
||||
<field name="purchased_quantity"/>
|
||||
<field name="remaining_quantity"/>
|
||||
<field name="denomination_origin" tree_invisible="1"/>
|
||||
</tree>
|
||||
|
|
|
@ -38,6 +38,9 @@
|
|||
<page name="beneficiaries">
|
||||
<field name="beneficiaries" colspan="4"/>
|
||||
</page>
|
||||
<page string="Parcel Distribution" id="parcel_distribution" >
|
||||
<field name="parcels" colspan="4"/>
|
||||
</page>
|
||||
</notebook>
|
||||
<label name="state"/>
|
||||
<field name="state"/>
|
||||
|
@ -45,7 +48,8 @@
|
|||
<button name="cancel" icon="tryton-cancel"/>
|
||||
<button name="draft"/>
|
||||
<button name="process" icon="tryton-forward"/>
|
||||
<button name="analysis" icon="tryton-forward"/>
|
||||
<button name="distribute" icon="tryton-forward"/>
|
||||
<button name="force_analysis" icon="tryton-forward"/>
|
||||
<button name="done" icon="tryton-forward"/>
|
||||
</group>
|
||||
</form>
|
||||
|
|
10
view/weighing_parcel_form.xml
Normal file
10
view/weighing_parcel_form.xml
Normal file
|
@ -0,0 +1,10 @@
|
|||
<form>
|
||||
<label name="weighing"/>
|
||||
<field name="weighing"/>
|
||||
<newline/>
|
||||
<label name="parcel"/>
|
||||
<field name="parcel"/>
|
||||
<newline/>
|
||||
<label name="netweight"/>
|
||||
<field name="netweight"/>
|
||||
</form>
|
6
view/weighing_parcel_list.xml
Normal file
6
view/weighing_parcel_list.xml
Normal file
|
@ -0,0 +1,6 @@
|
|||
<tree>
|
||||
<field name="weighing"/>
|
||||
<field name="parcel"/>
|
||||
<field name="netweight"/>
|
||||
<field name="table"/>
|
||||
</tree>
|
4
view/weighing_plantation_list.xml
Normal file
4
view/weighing_plantation_list.xml
Normal file
|
@ -0,0 +1,4 @@
|
|||
<tree sequence="sequence" editable="1">
|
||||
<field name="plantation"/>
|
||||
<field name="party"/>
|
||||
</tree>
|
133
weighing.py
133
weighing.py
|
@ -1,11 +1,13 @@
|
|||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
from trytond.model import fields, ModelSQL, ModelView, Workflow
|
||||
from trytond.model import fields, ModelSQL, ModelView, Workflow, sequence_ordered
|
||||
from trytond.pyson import Id, Eval, If
|
||||
from trytond.pool import Pool
|
||||
from trytond.i18n import gettext
|
||||
from trytond.exceptions import UserError
|
||||
from trytond.transaction import Transaction
|
||||
from trytond.wizard import (Wizard, StateView, StateTransition, StateAction,
|
||||
Button)
|
||||
from datetime import datetime
|
||||
|
||||
class WeighingCenter(ModelSQL, ModelView):
|
||||
|
@ -19,8 +21,8 @@ class WeighingCenter(ModelSQL, ModelView):
|
|||
])
|
||||
|
||||
|
||||
READONLY = ['processing', 'in_analysis', 'done', 'cancelled']
|
||||
READONLY2 = ['draft', 'in_analysis', 'done', 'cancelled']
|
||||
READONLY = ['processing', 'distributed', 'in_analysis', 'done', 'cancelled']
|
||||
READONLY2 = ['draft', 'distributed', 'in_analysis', 'done', 'cancelled']
|
||||
|
||||
class Weighing(Workflow, ModelSQL, ModelView):
|
||||
""" Weighing """
|
||||
|
@ -86,14 +88,15 @@ class Weighing(Workflow, ModelSQL, ModelView):
|
|||
'readonly': Eval('state').in_(READONLY2),
|
||||
'required': Eval('state') == 'in_analysis',
|
||||
})
|
||||
plantations = fields.Many2Many('agronomics.weighing-agronomics.plantation',
|
||||
'weighing', 'plantation', 'plantations', states={
|
||||
plantations = fields.One2Many('agronomics.weighing-agronomics.plantation',
|
||||
'weighing', 'plantations', states={
|
||||
'readonly': Eval('state').in_(READONLY),
|
||||
'required': Eval('state') == 'process',
|
||||
}, size=4)
|
||||
state = fields.Selection([
|
||||
('draft', "Draft"),
|
||||
('processing', "Processing"),
|
||||
('distributed', "Distributed"),
|
||||
('in_analysis', "In Analysis"),
|
||||
('done', "Done"),
|
||||
('cancelled', "Cancelled"),
|
||||
|
@ -107,6 +110,11 @@ class Weighing(Workflow, ModelSQL, ModelView):
|
|||
'get_quality_test', 'set_quality_test')
|
||||
product_created = fields.Many2One('product.product', 'Product Created',
|
||||
readonly=True)
|
||||
parcels = fields.One2Many('agronomics.weighing-agronomics.parcel',
|
||||
'weighing', 'Parcels', readonly=True)
|
||||
not_assigned_weight = fields.Function(
|
||||
fields.Float('Not Assigned Weight'), 'get_not_assigned_weight')
|
||||
forced_analysis = fields.Boolean('Forced Analysis', readonly=True)
|
||||
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
|
@ -118,6 +126,9 @@ class Weighing(Workflow, ModelSQL, ModelView):
|
|||
cls._transitions |= set((
|
||||
('draft', 'processing'),
|
||||
('processing', 'draft'),
|
||||
('processing', 'distributed'),
|
||||
('distributed', 'in_analysis'),
|
||||
('distributed', 'draft'),
|
||||
('processing', 'in_analysis'),
|
||||
('draft', 'cancelled'),
|
||||
('processing', 'cancelled'),
|
||||
|
@ -133,7 +144,7 @@ class Weighing(Workflow, ModelSQL, ModelView):
|
|||
'depends': ['state'],
|
||||
},
|
||||
'draft': {
|
||||
'invisible': ~Eval('state').in_(['processing']),
|
||||
'invisible': ~Eval('state').in_(['processing', 'distributed']),
|
||||
'icon': If(Eval('state') == 'cancelled',
|
||||
'tryton-undo',
|
||||
'tryton-back'),
|
||||
|
@ -143,10 +154,14 @@ class Weighing(Workflow, ModelSQL, ModelView):
|
|||
'invisible': Eval('state') != 'draft',
|
||||
'depends': ['state'],
|
||||
},
|
||||
'analysis': {
|
||||
'distribute': {
|
||||
'invisible': Eval('state') != 'processing',
|
||||
'depends': ['state'],
|
||||
},
|
||||
'force_analysis': {
|
||||
'invisible': Eval('state') != 'distributed',
|
||||
'depends': ['state'],
|
||||
},
|
||||
})
|
||||
|
||||
@staticmethod
|
||||
|
@ -173,7 +188,6 @@ class Weighing(Workflow, ModelSQL, ModelView):
|
|||
if not value:
|
||||
return
|
||||
|
||||
|
||||
@fields.depends('weighing_date')
|
||||
def on_change_with_crop(self):
|
||||
Crop = Pool().get('agronomics.crop')
|
||||
|
@ -186,8 +200,8 @@ class Weighing(Workflow, ModelSQL, ModelView):
|
|||
def get_parcel(self):
|
||||
if not self.plantations:
|
||||
return
|
||||
plantation = self.plantations[0]
|
||||
if not plantation.parcels:
|
||||
plantation = self.plantations[0].plantation
|
||||
if not plantation or not plantation.parcels:
|
||||
return
|
||||
return plantation.parcels[0]
|
||||
|
||||
|
@ -202,7 +216,7 @@ class Weighing(Workflow, ModelSQL, ModelView):
|
|||
def on_change_with_denomination_origin(self):
|
||||
parcel = self.get_parcel()
|
||||
if not parcel:
|
||||
return
|
||||
return []
|
||||
|
||||
return [x.id for x in parcel.denomination_origin]
|
||||
|
||||
|
@ -262,7 +276,7 @@ class Weighing(Workflow, ModelSQL, ModelView):
|
|||
if record.beneficiaries and abs(100 - round(percent, 2)) > 0.0001:
|
||||
raise UserError(gettext('agronomics.msg_beneficiaris_percent',
|
||||
crop=record.crop.rec_name,
|
||||
plantation=record.plantations[0].rec_name))
|
||||
plantation=record.plantations[0].plantation.rec_name))
|
||||
|
||||
@classmethod
|
||||
@Workflow.transition('in_analysis')
|
||||
|
@ -275,6 +289,9 @@ class Weighing(Workflow, ModelSQL, ModelView):
|
|||
with_rec_name=False)
|
||||
product = Product(**default_product_values)
|
||||
for weighing in weighings:
|
||||
if weighing.not_assigned_weight and not weighing.forced_analysis:
|
||||
raise UserError(gettext('agronomics.msg_not_assigned_weight',
|
||||
weighing=weighing.rec_name))
|
||||
product.template = weighing.product
|
||||
product.denominations_of_origin = weighing.denomination_origin
|
||||
if weighing.ecological:
|
||||
|
@ -293,6 +310,78 @@ class Weighing(Workflow, ModelSQL, ModelView):
|
|||
tests.append(weighing.create_quality_test())
|
||||
Quality.save(tests)
|
||||
|
||||
@classmethod
|
||||
@ModelView.button
|
||||
@Workflow.transition('distributed')
|
||||
def distribute(cls, weighings):
|
||||
pool = Pool()
|
||||
WeighingParcel = pool.get('agronomics.weighing-agronomics.parcel')
|
||||
weighing_parcel_to_save = []
|
||||
to_analysis = []
|
||||
for weighing in weighings:
|
||||
if not weighing.table:
|
||||
if weighing.parcels:
|
||||
WeighingParcel.delete(weighing.parcels)
|
||||
allowed_parcels = []
|
||||
remaining_weight = weighing.netweight
|
||||
for wp in weighing.plantations:
|
||||
plantation = wp.plantation
|
||||
if plantation:
|
||||
for parcel in plantation.parcels:
|
||||
if parcel.crop == weighing.crop:
|
||||
allowed_parcels.append(parcel)
|
||||
break
|
||||
for parcel in allowed_parcels:
|
||||
if not remaining_weight:
|
||||
break
|
||||
weighing_parcel = WeighingParcel()
|
||||
weighing_parcel.parcel = parcel
|
||||
weighing_parcel.weighing = weighing
|
||||
if parcel.remaining_quantity - remaining_weight >= 0:
|
||||
weighing_parcel.netweight = remaining_weight
|
||||
remaining_weight = 0
|
||||
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:
|
||||
parcel = weighing.get_parcel()
|
||||
weighing_parcel = WeighingParcel()
|
||||
weighing_parcel.parcel = parcel
|
||||
weighing_parcel.weighing = weighing
|
||||
weighing_parcel.netweight = weighing.netweight
|
||||
weighing_parcel.table = True
|
||||
weighing_parcel_to_save.append(weighing_parcel)
|
||||
to_analysis.append(weighing)
|
||||
WeighingParcel.save(weighing_parcel_to_save)
|
||||
cls.save(weighings)
|
||||
cls.analysis(to_analysis)
|
||||
|
||||
def get_not_assigned_weight(self, name):
|
||||
return self.netweight - sum([p.netweight for p in self.parcels])
|
||||
|
||||
@classmethod
|
||||
@ModelView.button
|
||||
def force_analysis(cls, weighings):
|
||||
to_copy_values = {}
|
||||
for weighing in weighings:
|
||||
to_copy_values[weighing.id] = {
|
||||
'netweight': weighing.not_assigned_weight}
|
||||
cls.copy(weighings, default={
|
||||
'netweight': lambda d: (
|
||||
to_copy_values[d['id']]['netweight']),
|
||||
'weight': None,
|
||||
'tara': None,
|
||||
})
|
||||
for weighing in weighings:
|
||||
weighing.forced_analysis = True
|
||||
weighing.netweight -= weighing.not_assigned_weight
|
||||
cls.save(weighings)
|
||||
cls.analysis(weighings)
|
||||
|
||||
def create_quality_test(self):
|
||||
pool = Pool()
|
||||
QualityTest = pool.get('quality.test')
|
||||
|
@ -371,6 +460,8 @@ class Weighing(Workflow, ModelSQL, ModelView):
|
|||
default = default.copy()
|
||||
default.setdefault('beneficiaries', None)
|
||||
default.setdefault('product_created', None)
|
||||
default.setdefault('number', None)
|
||||
default.setdefault('parcels', None)
|
||||
return super().copy(weighings, default=default)
|
||||
|
||||
|
||||
|
@ -383,10 +474,26 @@ class WeighingDo(ModelSQL):
|
|||
'Denomination Origin')
|
||||
|
||||
|
||||
class WeighingPlantation(ModelSQL):
|
||||
class WeighingPlantation(sequence_ordered(), ModelSQL, ModelView):
|
||||
'Weighing - Plantations'
|
||||
__name__ = 'agronomics.weighing-agronomics.plantation'
|
||||
|
||||
weighing = fields.Many2One('agronomics.weighing', 'Weighing')
|
||||
plantation = fields.Many2One('agronomics.plantation',
|
||||
'Plantation')
|
||||
party = fields.Function(fields.Many2One('party.party', 'Party'), 'get_party')
|
||||
|
||||
def get_party(self, name):
|
||||
if self.plantation:
|
||||
return self.plantation.party.id
|
||||
|
||||
|
||||
class WeighingParcel(ModelSQL, ModelView):
|
||||
"Weighing-Parcel"
|
||||
__name__ = 'agronomics.weighing-agronomics.parcel'
|
||||
|
||||
weighing = fields.Many2One('agronomics.weighing', 'Weighing',
|
||||
ondelete='CASCADE')
|
||||
parcel = fields.Many2One('agronomics.parcel', 'Parcel')
|
||||
netweight = fields.Float('Net Weight')
|
||||
table = fields.Boolean('Table')
|
||||
|
|
|
@ -168,16 +168,6 @@
|
|||
<field name="group" ref="group_agronomics"/>
|
||||
</record>
|
||||
|
||||
<record model="ir.model.button" id="weighing_analysis_button">
|
||||
<field name="name">analysis</field>
|
||||
<field name="string">Analysis</field>
|
||||
<field name="model" search="[('model', '=', 'agronomics.weighing')]"/>
|
||||
</record>
|
||||
<record model="ir.model.button-res.group" id="weighing_analysis_button_group_agronomics">
|
||||
<field name="button" ref="weighing_analysis_button"/>
|
||||
<field name="group" ref="group_agronomics"/>
|
||||
</record>
|
||||
|
||||
<record model="ir.model.button" id="weighing_cancel_button">
|
||||
<field name="name">cancel</field>
|
||||
<field name="string">Cancel</field>
|
||||
|
@ -198,5 +188,42 @@
|
|||
<field name="group" ref="group_agronomics"/>
|
||||
</record>
|
||||
|
||||
<record model="ir.model.button" id="weighing_distribute_button">
|
||||
<field name="name">distribute</field>
|
||||
<field name="string">Analysis</field>
|
||||
<field name="model" search="[('model', '=', 'agronomics.weighing')]"/>
|
||||
</record>
|
||||
<record model="ir.model.button-res.group" id="weighing_distribute_button_group_agronomics">
|
||||
<field name="button" ref="weighing_distribute_button"/>
|
||||
<field name="group" ref="group_agronomics"/>
|
||||
</record>
|
||||
|
||||
<record model="ir.model.button" id="weighing_force_analysis_button">
|
||||
<field name="name">force_analysis</field>
|
||||
<field name="string">Force Analysis</field>
|
||||
<field name="model" search="[('model', '=', 'agronomics.weighing')]"/>
|
||||
</record>
|
||||
<record model="ir.model.button-res.group" id="weighing_force_analysis_button_group_agronomics">
|
||||
<field name="button" ref="weighing_force_analysis_button"/>
|
||||
<field name="group" ref="group_agronomics"/>
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.view" id="weighing_parcel_view_form">
|
||||
<field name="model">agronomics.weighing-agronomics.parcel</field>
|
||||
<field name="type">form</field>
|
||||
<field name="name">weighing_parcel_form</field>
|
||||
</record>
|
||||
<record model="ir.ui.view" id="weighing_parcel_view_tree">
|
||||
<field name="model">agronomics.weighing-agronomics.parcel</field>
|
||||
<field name="type">tree</field>
|
||||
<field name="name">weighing_parcel_list</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.view" id="weighing_plantation_view_tree">
|
||||
<field name="model">agronomics.weighing-agronomics.plantation</field>
|
||||
<field name="type">tree</field>
|
||||
<field name="name">weighing_plantation_list</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</tryton>
|
||||
|
|
Loading…
Reference in a new issue