add wizard to create parcels from previous crop #060225
This commit is contained in:
parent
18792406b4
commit
b5dd42b0f6
|
@ -56,6 +56,7 @@ def register():
|
||||||
quality.QualityTest,
|
quality.QualityTest,
|
||||||
quality.QuantitativeTestLine,
|
quality.QuantitativeTestLine,
|
||||||
quality.QualitativeTestLine,
|
quality.QualitativeTestLine,
|
||||||
|
plot.CreateNewParcelsStart,
|
||||||
production.ProductionTemplate,
|
production.ProductionTemplate,
|
||||||
production.ProductionTemplateLine,
|
production.ProductionTemplateLine,
|
||||||
production.ProductionTemplateInputsProductTemplate,
|
production.ProductionTemplateInputsProductTemplate,
|
||||||
|
@ -74,6 +75,7 @@ def register():
|
||||||
module='agronomics', type_='model')
|
module='agronomics', type_='model')
|
||||||
Pool.register(
|
Pool.register(
|
||||||
production.ProductionCostPriceDistributionTemplateProductionTemplate,
|
production.ProductionCostPriceDistributionTemplateProductionTemplate,
|
||||||
|
plot.CreateNewParcels,
|
||||||
module='agronomics', type_='wizard')
|
module='agronomics', type_='wizard')
|
||||||
Pool.register(
|
Pool.register(
|
||||||
module='agronomics', type_='report')
|
module='agronomics', type_='report')
|
||||||
|
|
|
@ -149,8 +149,8 @@ class AgronomicsContractLine(ModelSQL, ModelView):
|
||||||
"Agronomics Contract Line"
|
"Agronomics Contract Line"
|
||||||
__name__ = 'agronomics.contract.line'
|
__name__ = 'agronomics.contract.line'
|
||||||
|
|
||||||
contract = fields.Many2One('agronomics.contract', 'Contract', required=True,
|
contract = fields.Many2One('agronomics.contract', 'Contract',
|
||||||
ondelete='CASCADE')
|
required=True, ondelete='CASCADE')
|
||||||
parcel = fields.Many2One('agronomics.parcel', "Parcel",
|
parcel = fields.Many2One('agronomics.parcel', "Parcel",
|
||||||
domain=[
|
domain=[
|
||||||
('producer', '=', Eval('_parent_contract.party')),
|
('producer', '=', Eval('_parent_contract.party')),
|
||||||
|
|
|
@ -1,9 +1,5 @@
|
||||||
from trytond.report import Report
|
from trytond.pool import PoolMeta
|
||||||
from trytond.pool import PoolMeta, Pool
|
|
||||||
from trytond.transaction import Transaction
|
|
||||||
from trytond.model import fields
|
from trytond.model import fields
|
||||||
from trytond.pyson import Eval, Bool
|
|
||||||
from decimal import Decimal
|
|
||||||
|
|
||||||
|
|
||||||
class InvoiceLine(metaclass=PoolMeta):
|
class InvoiceLine(metaclass=PoolMeta):
|
||||||
|
|
12
locale/ca.po
12
locale/ca.po
|
@ -544,6 +544,10 @@ msgctxt "field:product.product,needs_sample:"
|
||||||
msgid "Needs Samples"
|
msgid "Needs Samples"
|
||||||
msgstr "Necesita mostres"
|
msgstr "Necesita mostres"
|
||||||
|
|
||||||
|
msgctxt "field:product.product,production_quality_template:"
|
||||||
|
msgid "Production Quality Template"
|
||||||
|
msgstr "Plantilla Qualitat de producció"
|
||||||
|
|
||||||
msgctxt "field:product.product,quality_samples:"
|
msgctxt "field:product.product,quality_samples:"
|
||||||
msgid "Quality Samples"
|
msgid "Quality Samples"
|
||||||
msgstr "Mostres de qualitat"
|
msgstr "Mostres de qualitat"
|
||||||
|
@ -556,6 +560,14 @@ msgctxt "field:product.product,quality_weighing:"
|
||||||
msgid "Quality Weighing"
|
msgid "Quality Weighing"
|
||||||
msgstr "Qualitat Pesada"
|
msgstr "Qualitat Pesada"
|
||||||
|
|
||||||
|
msgctxt "field:product.product,shipment_in_quality_template:"
|
||||||
|
msgid "Shipment In Quality Template"
|
||||||
|
msgstr "Plantilla qualitat albarà entrada"
|
||||||
|
|
||||||
|
msgctxt "field:product.product,shipment_out_quality_template:"
|
||||||
|
msgid "Shipment Out Quality Template"
|
||||||
|
msgstr "Plantilla qualitat albarà sortida"
|
||||||
|
|
||||||
msgctxt "field:product.product,variant_deactivate_stock_zero:"
|
msgctxt "field:product.product,variant_deactivate_stock_zero:"
|
||||||
msgid "Variant Deactivate Stock 0"
|
msgid "Variant Deactivate Stock 0"
|
||||||
msgstr "Desactivar variant amb estoc a 0"
|
msgstr "Desactivar variant amb estoc a 0"
|
||||||
|
|
|
@ -544,6 +544,10 @@ msgctxt "field:product.product,needs_sample:"
|
||||||
msgid "Needs Samples"
|
msgid "Needs Samples"
|
||||||
msgstr "Requiere muestras"
|
msgstr "Requiere muestras"
|
||||||
|
|
||||||
|
msgctxt "field:product.product,production_quality_template:"
|
||||||
|
msgid "Production Quality Template"
|
||||||
|
msgstr "Plantilla calidad producción"
|
||||||
|
|
||||||
msgctxt "field:product.product,quality_samples:"
|
msgctxt "field:product.product,quality_samples:"
|
||||||
msgid "Quality Samples"
|
msgid "Quality Samples"
|
||||||
msgstr "Muestras de calidad"
|
msgstr "Muestras de calidad"
|
||||||
|
|
46
plot.py
46
plot.py
|
@ -1,8 +1,9 @@
|
||||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||||
# this repository contains the full copyright notices and license terms.
|
# this repository contains the full copyright notices and license terms.
|
||||||
from sql.aggregate import Min, Sum
|
from sql.aggregate import Sum
|
||||||
from trytond.model import fields, ModelSQL, ModelView
|
from trytond.model import fields, ModelSQL, ModelView
|
||||||
from trytond.pool import Pool
|
from trytond.pool import Pool
|
||||||
|
from trytond.wizard import (Wizard, StateView, Button, StateTransition)
|
||||||
|
|
||||||
|
|
||||||
class Enclosure(ModelSQL, ModelView):
|
class Enclosure(ModelSQL, ModelView):
|
||||||
|
@ -29,6 +30,12 @@ class Crop(ModelSQL, ModelView):
|
||||||
start_date = fields.Date('Start Date', required=True)
|
start_date = fields.Date('Start Date', required=True)
|
||||||
end_date = fields.Date('End 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):
|
class DenominationOrigin(ModelSQL, ModelView):
|
||||||
"Denomination of Origin"
|
"Denomination of Origin"
|
||||||
|
@ -133,13 +140,10 @@ class Plantation(ModelSQL, ModelView):
|
||||||
@classmethod
|
@classmethod
|
||||||
def search_remaining_quantity(cls, name, clause):
|
def search_remaining_quantity(cls, name, clause):
|
||||||
pool = Pool()
|
pool = Pool()
|
||||||
DO = pool.get('agronomics.denomination_of_origin')
|
|
||||||
PARCEL_DO = pool.get('agronomics.parcel-agronomics.do')
|
PARCEL_DO = pool.get('agronomics.parcel-agronomics.do')
|
||||||
Parcel = pool.get('agronomics.parcel')
|
Parcel = pool.get('agronomics.parcel')
|
||||||
Weighing = pool.get('agronomics.weighing-agronomics.parcel')
|
Weighing = pool.get('agronomics.weighing-agronomics.parcel')
|
||||||
MaxProductionAllowed = pool.get('agronomics.max.production.allowed')
|
MaxProductionAllowed = pool.get('agronomics.max.production.allowed')
|
||||||
|
|
||||||
do = DO.__table__()
|
|
||||||
parcel = Parcel.__table__()
|
parcel = Parcel.__table__()
|
||||||
parcel_do = PARCEL_DO.__table__()
|
parcel_do = PARCEL_DO.__table__()
|
||||||
weighing = Weighing.__table__()
|
weighing = Weighing.__table__()
|
||||||
|
@ -164,6 +168,7 @@ class Plantation(ModelSQL, ModelView):
|
||||||
query.where = Operator(query2.remaining_quantity, value)
|
query.where = Operator(query2.remaining_quantity, value)
|
||||||
return [('id' , 'in', query)]
|
return [('id' , 'in', query)]
|
||||||
|
|
||||||
|
|
||||||
class Ecological(ModelSQL, ModelView):
|
class Ecological(ModelSQL, ModelView):
|
||||||
"Ecological"
|
"Ecological"
|
||||||
__name__ = 'agronomics.ecological'
|
__name__ = 'agronomics.ecological'
|
||||||
|
@ -203,9 +208,11 @@ class Parcel(ModelSQL, ModelView):
|
||||||
weighings = fields.One2Many('agronomics.weighing-agronomics.parcel',
|
weighings = fields.One2Many('agronomics.weighing-agronomics.parcel',
|
||||||
'parcel', 'Weighings')
|
'parcel', 'Weighings')
|
||||||
purchased_quantity = fields.Function(
|
purchased_quantity = fields.Function(
|
||||||
fields.Float("Bought Quantity", digits=(16, 2)), 'get_purchased_quantity')
|
fields.Float("Bought Quantity", digits=(16, 2)),
|
||||||
|
'get_purchased_quantity')
|
||||||
remaining_quantity = fields.Function(
|
remaining_quantity = fields.Function(
|
||||||
fields.Float("Remainig Quantity", digits=(16, 2)), 'get_remaining_quantity')
|
fields.Float("Remainig Quantity", digits=(16, 2)),
|
||||||
|
'get_remaining_quantity')
|
||||||
|
|
||||||
def get_rec_name(self, name):
|
def get_rec_name(self, name):
|
||||||
if self.plantation and self.crop:
|
if self.plantation and self.crop:
|
||||||
|
@ -260,3 +267,30 @@ class Beneficiaries(ModelSQL, ModelView):
|
||||||
table.drop_column('percent')
|
table.drop_column('percent')
|
||||||
|
|
||||||
super(Beneficiaries, cls).__register__(module_name)
|
super(Beneficiaries, cls).__register__(module_name)
|
||||||
|
|
||||||
|
|
||||||
|
class CreateNewParcels(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 CreateNewParcelsStart(ModelView):
|
||||||
|
"Create New Parcels - 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)
|
||||||
|
|
18
plot.xml
18
plot.xml
|
@ -543,5 +543,21 @@
|
||||||
<field name="perm_create" eval="True"/>
|
<field name="perm_create" eval="True"/>
|
||||||
<field name="perm_delete" eval="True"/>
|
<field name="perm_delete" eval="True"/>
|
||||||
</record>
|
</record>
|
||||||
</data>
|
<record model="ir.action.wizard" id="wizard_create_new_parcels">
|
||||||
|
<field name="name">Create new Parcels</field>
|
||||||
|
<field name="wiz_name">agronomics.create_new_parcels</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<record model="ir.ui.view" id="create_new_parcels_start_form">
|
||||||
|
<field name="model">agronomics.create_new_parcels.start</field>
|
||||||
|
<field name="type">form</field>
|
||||||
|
<field name="name">create_new_parcels_start_form</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<menuitem
|
||||||
|
parent="agronomics.menu_crop_list"
|
||||||
|
action="wizard_create_new_parcels"
|
||||||
|
sequence="90"
|
||||||
|
id="menu_create_new_parcels"/>
|
||||||
|
</data>
|
||||||
</tryton>
|
</tryton>
|
||||||
|
|
|
@ -107,7 +107,8 @@ class Product(WineMixin, metaclass=PoolMeta):
|
||||||
'bottled-wine']
|
'bottled-wine']
|
||||||
)
|
)
|
||||||
}, depends=['agronomic_type'])
|
}, depends=['agronomic_type'])
|
||||||
alcohol_volume = fields.Function(fields.Numeric('Alcohol Volume', digits=(16, 2), states={
|
alcohol_volume = fields.Function(fields.Numeric('Alcohol Volume',
|
||||||
|
digits=(16, 2), states={
|
||||||
'invisible': ~ Eval('agronomic_type').in_(
|
'invisible': ~ Eval('agronomic_type').in_(
|
||||||
['wine', 'unfiltered-wine', 'filtered-wine', 'clarified-wine',
|
['wine', 'unfiltered-wine', 'filtered-wine', 'clarified-wine',
|
||||||
'bottled-wine']
|
'bottled-wine']
|
||||||
|
@ -155,7 +156,7 @@ class Product(WineMixin, metaclass=PoolMeta):
|
||||||
return Decimal(
|
return Decimal(
|
||||||
(float(self.template.capacity) * float(self.wine_alcohol_content))
|
(float(self.template.capacity) * float(self.wine_alcohol_content))
|
||||||
/ 100).quantize(
|
/ 100).quantize(
|
||||||
Decimal(str(10 ** -self.__class__.alcohol_volume.digits[1])))
|
Decimal(str(10 ** -self.__class__.alcohol_volume.digits[1])))
|
||||||
|
|
||||||
|
|
||||||
class Cron(metaclass=PoolMeta):
|
class Cron(metaclass=PoolMeta):
|
||||||
|
|
|
@ -0,0 +1,149 @@
|
||||||
|
===========================
|
||||||
|
Create new Parcel Scenario
|
||||||
|
===========================
|
||||||
|
|
||||||
|
Imports::
|
||||||
|
|
||||||
|
>>> import datetime
|
||||||
|
>>> from dateutil.relativedelta import relativedelta
|
||||||
|
>>> from decimal import Decimal
|
||||||
|
>>> from proteus import Model, Wizard
|
||||||
|
>>> from trytond.tests.tools import activate_modules
|
||||||
|
>>> from trytond.modules.company.tests.tools import create_company, \
|
||||||
|
... get_company
|
||||||
|
>>> from trytond.modules.production.production import BOM_CHANGES
|
||||||
|
>>> today = datetime.date.today()
|
||||||
|
>>> yesterday = today - relativedelta(days=1)
|
||||||
|
>>> before_yesterday = yesterday - relativedelta(days=1)
|
||||||
|
|
||||||
|
Activate modules::
|
||||||
|
|
||||||
|
>>> config = activate_modules('agronomics')
|
||||||
|
|
||||||
|
Create company::
|
||||||
|
|
||||||
|
>>> _ = create_company()
|
||||||
|
>>> company = get_company()
|
||||||
|
|
||||||
|
Create party::
|
||||||
|
|
||||||
|
>>> Party = Model.get('party.party')
|
||||||
|
>>> party = Party(name='Party')
|
||||||
|
>>> party.save()
|
||||||
|
|
||||||
|
Create product::
|
||||||
|
|
||||||
|
>>> ProductUom = Model.get('product.uom')
|
||||||
|
>>> liter, = ProductUom.find([('name', '=', 'Liter')])
|
||||||
|
>>> kg, = ProductUom.find([('name', '=', 'Kilogram')])
|
||||||
|
|
||||||
|
>>> ProductTemplate = Model.get('product.template')
|
||||||
|
>>> Product = Model.get('product.product')
|
||||||
|
>>> Taxon = Model.get('product.taxon')
|
||||||
|
>>> DO = Model.get('agronomics.denomination_of_origin')
|
||||||
|
>>> Ecological = Model.get('agronomics.ecological')
|
||||||
|
|
||||||
|
Create Denomination Of Origin::
|
||||||
|
|
||||||
|
>>> catalunya = DO()
|
||||||
|
>>> catalunya.name = 'Catalunya'
|
||||||
|
>>> catalunya.save()
|
||||||
|
|
||||||
|
>>> barcelona = DO()
|
||||||
|
>>> barcelona.name = 'Barcelona'
|
||||||
|
>>> barcelona.save()
|
||||||
|
|
||||||
|
Create Specie::
|
||||||
|
|
||||||
|
>>> species = Taxon()
|
||||||
|
>>> species.rank = 'species'
|
||||||
|
>>> species.name = 'Species'
|
||||||
|
>>> species.save()
|
||||||
|
|
||||||
|
Create Variety::
|
||||||
|
|
||||||
|
>>> macabeu = Taxon()
|
||||||
|
>>> macabeu.rank = 'variety'
|
||||||
|
>>> macabeu.name = 'Macabeu'
|
||||||
|
>>> macabeu.save()
|
||||||
|
|
||||||
|
>>> parellada = Taxon()
|
||||||
|
>>> parellada.rank = 'variety'
|
||||||
|
>>> parellada.name = 'Parellada'
|
||||||
|
>>> parellada.save()
|
||||||
|
|
||||||
|
Create Ecological::
|
||||||
|
|
||||||
|
>>> ecological = Ecological()
|
||||||
|
>>> ecological.name = 'Ecological'
|
||||||
|
>>> ecological.save()
|
||||||
|
|
||||||
|
Create Crop::
|
||||||
|
|
||||||
|
>>> Crop = Model.get('agronomics.crop')
|
||||||
|
>>> crop = Crop()
|
||||||
|
>>> crop.name = str(today.year)
|
||||||
|
>>> crop.code = str(today.year)
|
||||||
|
>>> crop.start_date = datetime.date(today.year, 1, 1)
|
||||||
|
>>> crop.end_date = datetime.date(today.year, 12, 31)
|
||||||
|
>>> crop.save()
|
||||||
|
|
||||||
|
Create Next Crop::
|
||||||
|
|
||||||
|
>>> next_crop = Crop()
|
||||||
|
>>> next_crop.name = str(today.year + 1)
|
||||||
|
>>> next_crop.code = str(today.year + 1)
|
||||||
|
>>> next_crop.start_date = datetime.date(today.year +1 , 1, 1)
|
||||||
|
>>> next_crop.end_date = datetime.date(today.year +1, 12, 31)
|
||||||
|
>>> next_crop.save()
|
||||||
|
|
||||||
|
Create Plantation::
|
||||||
|
|
||||||
|
>>> Plantation = Model.get('agronomics.plantation')
|
||||||
|
>>> plantation = Plantation()
|
||||||
|
>>> plantation.party = party
|
||||||
|
>>> plantation.code = 'Plantation'
|
||||||
|
>>> plantation.plantation_year = today.year
|
||||||
|
>>> enclosure = plantation.enclosures.new()
|
||||||
|
>>> enclosure = plantation.enclosures.new()
|
||||||
|
>>> parcel = plantation.parcels.new()
|
||||||
|
>>> parcel.crop = crop
|
||||||
|
>>> parcel.species = species
|
||||||
|
>>> parcel.variety = macabeu
|
||||||
|
>>> parcel.ecological = ecological
|
||||||
|
>>> parcel.surface = 100
|
||||||
|
>>> parcel2 = plantation.parcels.new()
|
||||||
|
>>> parcel2.crop = crop
|
||||||
|
>>> parcel2.species = species
|
||||||
|
>>> parcel2.variety = macabeu
|
||||||
|
>>> parcel2.ecological = ecological
|
||||||
|
>>> parcel2.surface = 200
|
||||||
|
>>> plantation.save()
|
||||||
|
|
||||||
|
Search for parcels::
|
||||||
|
|
||||||
|
>>> Parcel = Model.get('agronomics.parcel')
|
||||||
|
>>> parcels = Parcel.find([])
|
||||||
|
>>> len(parcels)
|
||||||
|
2
|
||||||
|
|
||||||
|
Create New Parcels for next Year::
|
||||||
|
|
||||||
|
>>> wizard = Wizard('agronomics.create_new_parcels')
|
||||||
|
>>> wizard.form.previous_crop = crop
|
||||||
|
>>> wizard.form.next_crop = next_crop
|
||||||
|
>>> wizard.execute('copy_parcels')
|
||||||
|
|
||||||
|
Search for parcels::
|
||||||
|
|
||||||
|
>>> Parcel = Model.get('agronomics.parcel')
|
||||||
|
>>> parcels = Parcel.find([])
|
||||||
|
>>> len(parcels)
|
||||||
|
4
|
||||||
|
|
||||||
|
Search 2 parcels from next_crop::
|
||||||
|
|
||||||
|
>>> Parcel = Model.get('agronomics.parcel')
|
||||||
|
>>> parcels = Parcel.find([('crop', '=', next_crop.id)])
|
||||||
|
>>> len(parcels)
|
||||||
|
2
|
|
@ -0,0 +1,6 @@
|
||||||
|
<form>
|
||||||
|
<label name="previous_crop"/>
|
||||||
|
<field name="previous_crop"/>
|
||||||
|
<label name="next_crop"/>
|
||||||
|
<field name="next_crop"/>
|
||||||
|
</form>
|
Loading…
Reference in New Issue