Add default value for breed on animal and animal group

This commit is contained in:
Sergi Almacellas Abellana 2015-05-05 16:56:17 +02:00
parent cdbac8ee0f
commit 9a0031604f
2 changed files with 20 additions and 0 deletions

View File

@ -233,6 +233,16 @@ class Animal(ModelSQL, ModelView, AnimalMixin):
def default_specie():
return Transaction().context.get('specie')
@staticmethod
def default_breed():
pool = Pool()
Specie = pool.get('farm.specie')
context = Transaction().context
if 'specie' in context:
specie = Specie(context['specie'])
if len(specie.breeds) == 1:
return specie.breeds[0].id
@staticmethod
def default_type():
return Transaction().context.get('animal_type')

View File

@ -126,6 +126,16 @@ class AnimalGroup(ModelSQL, ModelView, AnimalMixin):
def default_specie():
return Transaction().context.get('specie')
@staticmethod
def default_breed():
pool = Pool()
Specie = pool.get('farm.specie')
context = Transaction().context
if 'specie' in context:
specie = Specie(context['specie'])
if len(specie.breeds) == 1:
return specie.breeds[0].id
@staticmethod
def default_origin():
return 'purchased'