si un seul code financier est trouvé pour l'entité choisie, on l'utilise par défaut dans la demande
This commit is contained in:
parent
08f0935ded
commit
877eda27ed
|
@ -60,7 +60,7 @@ class Entity(models.Model):
|
|||
return a set of "accounting" codes: one of the entity and those of all its parents
|
||||
'''
|
||||
for parent in self.parents(included=True).order_by('-depth').prefetch_related('accountingcode_set'):
|
||||
if parent.accountingcode_set.exists():
|
||||
if parent.accountingcode_set.all():
|
||||
return parent.accountingcode_set.all()
|
||||
return AccountingCode.objects.none()
|
||||
|
||||
|
|
|
@ -177,6 +177,14 @@ class ReproOriginForm(BaseModelForm):
|
|||
Field('sponsor', css_class='span12'),
|
||||
Field('entity', template = 'entityselector.html', **{'data-frequent-values': json.dumps(self.frequent_entities)}))
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
if self.instance.entity:
|
||||
codes = self.instance.entity.accounting_codes()
|
||||
if len(codes) == 1:
|
||||
self.instance.financial_code = codes[0].code
|
||||
super(ReproOriginForm, self).save(*args, **kwargs)
|
||||
|
||||
|
||||
class ReproDetailsForm(BaseModelForm):
|
||||
class Meta:
|
||||
model = Request
|
||||
|
|
Reference in New Issue