diff --git a/__init__.py b/__init__.py index e282cbe..98dfd4d 100644 --- a/__init__.py +++ b/__init__.py @@ -54,6 +54,7 @@ def register(): quality.QualityTest, quality.QuantitativeTestLine, quality.QualitativeTestLine, + plot.CreateNewParcelStart, production.ProductionTemplate, production.ProductionTemplateLine, production.ProductionTemplateInputsProductTemplate, @@ -62,7 +63,6 @@ def register(): production.OutputDistribution, production.ProductionEnologyProduct, production.ProductionCostPriceDistribution, -# production.ProductionProductionCostPriceDistribution, production.ProductionCostPriceDistributionTemplate, production.ProductionCostPriceDistributionTemplateProductionTemplateAsk, location.LocationMaterial, @@ -72,6 +72,7 @@ def register(): module='agronomics', type_='model') Pool.register( production.ProductionCostPriceDistributionTemplateProductionTemplate, + plot.CreateNewParcel, module='agronomics', type_='wizard') Pool.register( module='agronomics', type_='report') diff --git a/plot.py b/plot.py index b31772d..70635f7 100644 --- a/plot.py +++ b/plot.py @@ -2,7 +2,7 @@ # this repository contains the full copyright notices and license terms. from trytond.model import fields, ModelSQL, ModelView from trytond.pool import Pool - +from trytond.wizard import (Wizard, StateView, Button, StateTransition) class Enclosure(ModelSQL, ModelView): "Enclosure" @@ -28,6 +28,13 @@ class Crop(ModelSQL, ModelView): start_date = fields.Date('Start Date', required=True) end_date = fields.Date('End Date', required=True) + def copy_parcels(self, next_crop): + pool = Pool() + Parcel = pool.get('agronomics.parcel') + parcels = Parcel.search([('crop' ,'=', self.id)]) + Parcel.copy(parcels, {'crop': next_crop}) + + class DenominationOrigin(ModelSQL, ModelView): "Denomination of Origin" @@ -171,3 +178,29 @@ class Beneficiaries(ModelSQL, ModelView): table.drop_column('percent') super(Beneficiaries, cls).__register__(module_name) + +class CreateNewParcel(Wizard): + 'New Version' + __name__ = 'agronomics.create_new_parcels' + + start = StateView('agronomics.create_new_parcels.start', + 'agronomics.create_new_parcels_start_form', [ + Button('Cancel', 'end', 'tryton-cancel'), + Button('Create', 'copy_parcels', 'tryton-accept', default=True), + ]) + copy_parcels = StateTransition() + + def transition_copy_parcels(self): + crop = self.start.previous_crop + crop.copy_parcels(self.start.next_crop) + return 'end' + + +class CreateNewParcelStart(ModelView): + "Create New Parcel - Start" + __name__ = 'agronomics.create_new_parcels.start' + + previous_crop = fields.Many2One('agronomics.crop', "Previous Crop", + required=True) + next_crop = fields.Many2One('agronomics.crop', "Next Crop", + required=True) diff --git a/plot.xml b/plot.xml index 60a2bc4..b30f65f 100644 --- a/plot.xml +++ b/plot.xml @@ -543,5 +543,23 @@ + + + Create new Parcels + agronomics.create_new_parcels + + + + agronomics.create_new_parcels.start + form + create_new_parcels_start_form + + + + diff --git a/view/create_new_parcels_start_form.xml b/view/create_new_parcels_start_form.xml new file mode 100644 index 0000000..d1d14d3 --- /dev/null +++ b/view/create_new_parcels_start_form.xml @@ -0,0 +1,6 @@ +
+