forked from DGNum/gestioCOF
Nouvel article - Sélection(et/ou création) de fournisseurs
This commit is contained in:
parent
be8243c4ce
commit
ab9bbac34f
7 changed files with 99 additions and 16 deletions
|
@ -8,7 +8,7 @@ from django.forms.models import BaseInlineFormSet
|
|||
from django.utils import timezone
|
||||
from kfet.models import (Account, Checkout, Article, OperationGroup, Operation,
|
||||
CheckoutStatement, ArticleCategory, Settings, AccountNegative, Transfer,
|
||||
TransferGroup)
|
||||
TransferGroup, Supplier)
|
||||
from gestioncof.models import CofProfile
|
||||
|
||||
# -----
|
||||
|
@ -192,6 +192,18 @@ class ArticleForm(forms.ModelForm):
|
|||
queryset = ArticleCategory.objects.all(),
|
||||
required = False)
|
||||
|
||||
suppliers = forms.ModelMultipleChoiceField(
|
||||
queryset = Supplier.objects.all(),
|
||||
required = False)
|
||||
supplier_new = forms.CharField(
|
||||
max_length = 45,
|
||||
required = False)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(ArticleForm, self).__init__(*args, **kwargs)
|
||||
if self.instance.pk:
|
||||
self.initial['suppliers'] = self.instance.suppliers.values_list('pk', flat=True)
|
||||
|
||||
def clean(self):
|
||||
category = self.cleaned_data.get('category')
|
||||
category_new = self.cleaned_data.get('category_new')
|
||||
|
@ -201,6 +213,7 @@ class ArticleForm(forms.ModelForm):
|
|||
elif not category:
|
||||
category, _ = ArticleCategory.objects.get_or_create(name=category_new)
|
||||
self.cleaned_data['category'] = category
|
||||
|
||||
super(ArticleForm, self).clean()
|
||||
|
||||
class Meta:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue