add wizard to create parcels from previous crop #060225
This commit is contained in:
parent
1fac0a8145
commit
fb91f63559
|
@ -56,6 +56,7 @@ def register():
|
|||
quality.QualityTest,
|
||||
quality.QuantitativeTestLine,
|
||||
quality.QualitativeTestLine,
|
||||
plot.CreateNewParcelsStart,
|
||||
production.ProductionTemplate,
|
||||
production.ProductionTemplateLine,
|
||||
production.ProductionTemplateInputsProductTemplate,
|
||||
|
@ -74,6 +75,7 @@ def register():
|
|||
module='agronomics', type_='model')
|
||||
Pool.register(
|
||||
production.ProductionCostPriceDistributionTemplateProductionTemplate,
|
||||
plot.CreateNewParcels,
|
||||
module='agronomics', type_='wizard')
|
||||
Pool.register(
|
||||
module='agronomics', type_='report')
|
||||
|
|
|
@ -149,8 +149,8 @@ class AgronomicsContractLine(ModelSQL, ModelView):
|
|||
"Agronomics Contract Line"
|
||||
__name__ = 'agronomics.contract.line'
|
||||
|
||||
contract = fields.Many2One('agronomics.contract', 'Contract', required=True,
|
||||
ondelete='CASCADE')
|
||||
contract = fields.Many2One('agronomics.contract', 'Contract',
|
||||
required=True, ondelete='CASCADE')
|
||||
parcel = fields.Many2One('agronomics.parcel', "Parcel",
|
||||
domain=[
|
||||
('producer', '=', Eval('_parent_contract.party')),
|
||||
|
|
|
@ -1,9 +1,5 @@
|
|||
from trytond.report import Report
|
||||
from trytond.pool import PoolMeta, Pool
|
||||
from trytond.transaction import Transaction
|
||||
from trytond.pool import PoolMeta
|
||||
from trytond.model import fields
|
||||
from trytond.pyson import Eval, Bool
|
||||
from decimal import Decimal
|
||||
|
||||
|
||||
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"
|
||||
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:"
|
||||
msgid "Quality Samples"
|
||||
msgstr "Mostres de qualitat"
|
||||
|
@ -556,6 +560,14 @@ msgctxt "field:product.product,quality_weighing:"
|
|||
msgid "Quality Weighing"
|
||||
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:"
|
||||
msgid "Variant Deactivate Stock 0"
|
||||
msgstr "Desactivar variant amb estoc a 0"
|
||||
|
|
|
@ -544,6 +544,10 @@ msgctxt "field:product.product,needs_sample:"
|
|||
msgid "Needs Samples"
|
||||
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:"
|
||||
msgid "Quality Samples"
|
||||
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 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.pool import Pool
|
||||
from trytond.wizard import (Wizard, StateView, Button, StateTransition)
|
||||
|
||||
|
||||
class Enclosure(ModelSQL, ModelView):
|
||||
|
@ -29,6 +30,12 @@ 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"
|
||||
|
@ -133,13 +140,10 @@ class Plantation(ModelSQL, ModelView):
|
|||
@classmethod
|
||||
def search_remaining_quantity(cls, name, clause):
|
||||
pool = Pool()
|
||||
DO = pool.get('agronomics.denomination_of_origin')
|
||||
PARCEL_DO = pool.get('agronomics.parcel-agronomics.do')
|
||||
Parcel = pool.get('agronomics.parcel')
|
||||
Weighing = pool.get('agronomics.weighing-agronomics.parcel')
|
||||
MaxProductionAllowed = pool.get('agronomics.max.production.allowed')
|
||||
|
||||
do = DO.__table__()
|
||||
parcel = Parcel.__table__()
|
||||
parcel_do = PARCEL_DO.__table__()
|
||||
weighing = Weighing.__table__()
|
||||
|
@ -164,6 +168,7 @@ class Plantation(ModelSQL, ModelView):
|
|||
query.where = Operator(query2.remaining_quantity, value)
|
||||
return [('id' , 'in', query)]
|
||||
|
||||
|
||||
class Ecological(ModelSQL, ModelView):
|
||||
"Ecological"
|
||||
__name__ = 'agronomics.ecological'
|
||||
|
@ -203,9 +208,11 @@ class Parcel(ModelSQL, ModelView):
|
|||
weighings = fields.One2Many('agronomics.weighing-agronomics.parcel',
|
||||
'parcel', 'Weighings')
|
||||
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(
|
||||
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):
|
||||
if self.plantation and self.crop:
|
||||
|
@ -260,3 +267,30 @@ class Beneficiaries(ModelSQL, ModelView):
|
|||
table.drop_column('percent')
|
||||
|
||||
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_delete" eval="True"/>
|
||||
</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>
|
||||
|
|
|
@ -107,7 +107,8 @@ class Product(WineMixin, metaclass=PoolMeta):
|
|||
'bottled-wine']
|
||||
)
|
||||
}, 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_(
|
||||
['wine', 'unfiltered-wine', 'filtered-wine', 'clarified-wine',
|
||||
'bottled-wine']
|
||||
|
@ -155,7 +156,7 @@ class Product(WineMixin, metaclass=PoolMeta):
|
|||
return Decimal(
|
||||
(float(self.template.capacity) * float(self.wine_alcohol_content))
|
||||
/ 100).quantize(
|
||||
Decimal(str(10 ** -self.__class__.alcohol_volume.digits[1])))
|
||||
Decimal(str(10 ** -self.__class__.alcohol_volume.digits[1])))
|
||||
|
||||
|
||||
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