232 lines
7.4 KiB
ReStructuredText
232 lines
7.4 KiB
ReStructuredText
==========================
|
|
Nutrition Program Scenario
|
|
==========================
|
|
|
|
=============
|
|
General Setup
|
|
=============
|
|
|
|
Imports::
|
|
|
|
>>> import datetime
|
|
>>> from dateutil.relativedelta import relativedelta
|
|
>>> from decimal import Decimal
|
|
>>> from proteus import config, Model, Wizard
|
|
>>> now = datetime.datetime.now()
|
|
>>> yesterday = datetime.datetime.now() - relativedelta(days=1)
|
|
>>> today = datetime.date.today()
|
|
|
|
Create database::
|
|
|
|
>>> config = config.set_trytond()
|
|
>>> config.pool.test = True
|
|
|
|
Install farm::
|
|
|
|
>>> Module = Model.get('ir.module.module')
|
|
>>> modules = Module.find([
|
|
... ('name', '=', 'farm_nutrition_program'),
|
|
... ])
|
|
>>> Module.install([x.id for x in modules], config.context)
|
|
>>> Wizard('ir.module.module.install_upgrade').execute('upgrade')
|
|
|
|
Create company::
|
|
|
|
>>> Currency = Model.get('currency.currency')
|
|
>>> CurrencyRate = Model.get('currency.currency.rate')
|
|
>>> Company = Model.get('company.company')
|
|
>>> Party = Model.get('party.party')
|
|
>>> company_config = Wizard('company.company.config')
|
|
>>> company_config.execute('company')
|
|
>>> company = company_config.form
|
|
>>> party = Party(name='NaN·tic')
|
|
>>> party.save()
|
|
>>> company.party = party
|
|
>>> currencies = Currency.find([('code', '=', 'EUR')])
|
|
>>> if not currencies:
|
|
... currency = Currency(name='Euro', symbol=u'€', code='EUR',
|
|
... rounding=Decimal('0.01'), mon_grouping='[3, 3, 0]',
|
|
... mon_decimal_point=',')
|
|
... currency.save()
|
|
... CurrencyRate(date=now.date() + relativedelta(month=1, day=1),
|
|
... rate=Decimal('1.0'), currency=currency).save()
|
|
... else:
|
|
... currency, = currencies
|
|
>>> company.currency = currency
|
|
>>> company_config.execute('add')
|
|
>>> company, = Company.find()
|
|
|
|
Reload the context::
|
|
|
|
>>> User = Model.get('res.user')
|
|
>>> config._context = User.get_preferences(True, config.context)
|
|
|
|
Create products::
|
|
|
|
>>> ProductUom = Model.get('product.uom')
|
|
>>> unit, = ProductUom.find([('name', '=', 'Unit')])
|
|
>>> ProductTemplate = Model.get('product.template')
|
|
>>> Product = Model.get('product.product')
|
|
>>> individual_template = ProductTemplate(
|
|
... name='Male Pig',
|
|
... default_uom=unit,
|
|
... type='goods',
|
|
... list_price=Decimal('40'),
|
|
... cost_price=Decimal('25'))
|
|
>>> individual_template.save()
|
|
>>> individual_product = Product(template=individual_template)
|
|
>>> individual_product.save()
|
|
>>> group_template = ProductTemplate(
|
|
... name='Group of Pig',
|
|
... default_uom=unit,
|
|
... type='goods',
|
|
... list_price=Decimal('30'),
|
|
... cost_price=Decimal('20'))
|
|
>>> group_template.save()
|
|
>>> group_product = Product(template=group_template)
|
|
>>> group_product.save()
|
|
>>> grain_template = ProductTemplate(
|
|
... name='Graing',
|
|
... default_uom=unit,
|
|
... type='goods',
|
|
... list_price=Decimal('40'),
|
|
... cost_price=Decimal('25'))
|
|
>>> grain_template.save()
|
|
>>> grain_product = Product(template=grain_template)
|
|
>>> grain_product.save()
|
|
|
|
Create sequence::
|
|
|
|
>>> Sequence = Model.get('ir.sequence')
|
|
>>> event_order_sequence = Sequence(
|
|
... name='Event Order Pig Warehouse 1',
|
|
... code='farm.event.order',
|
|
... padding=4)
|
|
>>> event_order_sequence.save()
|
|
>>> individual_sequence = Sequence(
|
|
... name='Individual Pig Warehouse 1',
|
|
... code='farm.animal',
|
|
... padding=4)
|
|
>>> individual_sequence.save()
|
|
>>> group_sequence = Sequence(
|
|
... name='Groups Pig Warehouse 1',
|
|
... code='farm.animal.group',
|
|
... padding=4)
|
|
>>> group_sequence.save()
|
|
|
|
Create specie::
|
|
|
|
>>> Location = Model.get('stock.location')
|
|
>>> lost_found_location, = Location.find([('type', '=', 'lost_found')])
|
|
>>> warehouse, = Location.find([('type', '=', 'warehouse')])
|
|
>>> Specie = Model.get('farm.specie')
|
|
>>> SpecieBreed = Model.get('farm.specie.breed')
|
|
>>> SpecieFarmLine = Model.get('farm.specie.farm_line')
|
|
>>> pigs_specie = Specie(
|
|
... name='Pigs',
|
|
... male_enabled=False,
|
|
... female_enabled=False,
|
|
... individual_enabled=True,
|
|
... individual_product=individual_product,
|
|
... group_enabled=True,
|
|
... group_product=group_product,
|
|
... removed_location=lost_found_location,
|
|
... foster_location=lost_found_location,
|
|
... lost_found_location=lost_found_location,
|
|
... feed_lost_found_location=lost_found_location)
|
|
>>> pigs_specie.save()
|
|
>>> pigs_breed = SpecieBreed(
|
|
... specie=pigs_specie,
|
|
... name='Holland')
|
|
>>> pigs_breed.save()
|
|
>>> pigs_farm_line = SpecieFarmLine(
|
|
... specie=pigs_specie,
|
|
... farm=warehouse,
|
|
... event_order_sequence=event_order_sequence,
|
|
... has_individual=True,
|
|
... individual_sequence=individual_sequence,
|
|
... has_group=True,
|
|
... group_sequence=group_sequence)
|
|
>>> pigs_farm_line.save()
|
|
|
|
Create farm locations::
|
|
|
|
>>> location1_id, location2_id = Location.create([{
|
|
... 'name': 'Location 1',
|
|
... 'code': 'L1',
|
|
... 'type': 'storage',
|
|
... 'parent': warehouse.storage_location.id,
|
|
... }, {
|
|
... 'name': 'Location 2',
|
|
... 'code': 'L2',
|
|
... 'type': 'storage',
|
|
... 'parent': warehouse.storage_location.id,
|
|
... }], config.context)
|
|
|
|
Create individual::
|
|
|
|
>>> Animal = Model.get('farm.animal')
|
|
>>> individual = Animal(
|
|
... type='individual',
|
|
... specie=pigs_specie,
|
|
... breed=pigs_breed,
|
|
... number='0001',
|
|
... initial_location=location1_id)
|
|
>>> individual.save()
|
|
>>> individual.location.code
|
|
u'L1'
|
|
>>> individual.farm.code
|
|
u'WH'
|
|
>>> individual.nutrition_program == None
|
|
True
|
|
|
|
Create nutrition program::
|
|
|
|
>>> NutritionProgram = Model.get('farm.nutrition.program')
|
|
>>> nutrition_program = NutritionProgram(
|
|
... specie=pigs_specie,
|
|
... animal_type='individual',
|
|
... start_weight=10.0,
|
|
... end_weight=30.0,
|
|
... product=grain_product)
|
|
>>> nutrition_program.save()
|
|
>>> individual.nutrition_program == None
|
|
True
|
|
|
|
Add weight on animal::
|
|
|
|
>>> AnimalWeight = Model.get('farm.animal.weight')
|
|
>>> kg, = ProductUom.find([('name', '=', 'Kilogram')])
|
|
>>> weight = AnimalWeight(animal=individual,
|
|
... timestamp=yesterday,
|
|
... uom=kg,
|
|
... weight=Decimal('15.0'))
|
|
>>> weight.save()
|
|
>>> individual.reload()
|
|
>>> individual.current_weight.weight == Decimal('15.0')
|
|
True
|
|
>>> individual.nutrition_program == nutrition_program
|
|
True
|
|
|
|
Create another nutrition program::
|
|
|
|
>>> nutrition_program2 = NutritionProgram(
|
|
... specie=pigs_specie,
|
|
... animal_type='individual',
|
|
... start_weight=50.0,
|
|
... end_weight=70.0,
|
|
... product=grain_product)
|
|
>>> nutrition_program2.save()
|
|
>>> AnimalWeight = Model.get('farm.animal.weight')
|
|
>>> kg, = ProductUom.find([('name', '=', 'Kilogram')])
|
|
>>> weight = AnimalWeight(animal=individual,
|
|
... timestamp=now,
|
|
... uom=kg,
|
|
... weight=Decimal('60.0'))
|
|
>>> weight.save()
|
|
>>> individual.reload()
|
|
>>> individual.current_weight.weight == Decimal('60.0')
|
|
True
|
|
>>> individual.nutrition_program == nutrition_program2
|
|
True
|