add test
This commit is contained in:
parent
994c14689b
commit
f3306900fc
|
@ -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):
|
||||
|
|
16
plot.py
16
plot.py
|
@ -1,6 +1,6 @@
|
|||
# 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)
|
||||
|
@ -76,11 +76,6 @@ class Plantation(ModelSQL, ModelView):
|
|||
parcels = fields.One2Many('agronomics.parcel', 'plantation', "Parcel")
|
||||
plantation_year = fields.Integer("Plantation Year")
|
||||
plantation_owner = fields.Many2One('party.party', "Plantation Owner")
|
||||
|
||||
def get_rec_name(self, name):
|
||||
if self.code:
|
||||
return self.code
|
||||
return self.name
|
||||
varieties = fields.Function(fields.Char('Varieties'), 'get_varieties',
|
||||
searcher='search_varieties')
|
||||
do = fields.Function(fields.Char('DO'), 'get_do', searcher='search_do')
|
||||
|
@ -145,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__()
|
||||
|
@ -216,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:
|
||||
|
|
|
@ -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
|
Loading…
Reference in New Issue