8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-22 11:23:10 +00:00

Merge branch 'fix_js_vente' into 'dev'

Fix js vente

See merge request federez/re2o!478
This commit is contained in:
Yoann Pétri 2019-12-27 18:09:49 +01:00
commit aa63561a62
5 changed files with 19 additions and 13 deletions

View file

@ -795,7 +795,7 @@ class UserSerializer(NamespacedHMSerializer):
"access", "access",
"end_access", "end_access",
"uid", "uid",
"class_name", "class_type",
"api_url", "api_url",
) )
extra_kwargs = {"shell": {"view_name": "shell-detail"}} extra_kwargs = {"shell": {"view_name": "shell-detail"}}

View file

@ -775,7 +775,7 @@ class Article(RevMixin, AclMixin, models.Model):
target_user: The user to sell articles target_user: The user to sell articles
""" """
if target_user is None: if target_user is None:
objects_pool = cls.objects.filter(Q(type_user="All")) objects_pool = cls.objects.all()
elif target_user.is_class_club: elif target_user.is_class_club:
objects_pool = cls.objects.filter(Q(type_user="All") | Q(type_user="Club")) objects_pool = cls.objects.filter(Q(type_user="All") | Q(type_user="Club"))
else: else:

View file

@ -87,7 +87,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{% if articlesformset %} {% if articlesformset %}
var prices = {}; var prices = {};
{% for article in articlelist %} {% for article in articlelist %}
prices[{{ article.id|escapejs }}] = {{ article.prix }}; prices[{{ article.id|escapejs }}] = "{{ article.prix }}";
{% endfor %} {% endfor %}
var template = `Article :   var template = `Article :  
@ -121,7 +121,7 @@ function update_price(){
if (article == '') { if (article == '') {
continue; continue;
} }
article_price = prices[article]; article_price = parseFloat(prices[article].replace(',', '.'));
quantity = document.getElementById( quantity = document.getElementById(
'id_form-' + i.toString() + '-quantity').value; 'id_form-' + i.toString() + '-quantity').value;
price += article_price * quantity; price += article_price * quantity;

View file

@ -102,7 +102,7 @@ def new_facture(request, user, userid):
invoice = Facture(user=user) invoice = Facture(user=user)
# The template needs the list of articles (for the JS part) # The template needs the list of articles (for the JS part)
article_list = Article.objects.filter( article_list = Article.objects.filter(
Q(type_user="All") | Q(type_user=request.user.class_name) Q(type_user="All") | Q(type_user=user.class_type)
) )
# Building the invoice form and the article formset # Building the invoice form and the article formset
invoice_form = FactureForm( invoice_form = FactureForm(
@ -184,9 +184,7 @@ def new_cost_estimate(request):
point of view. point of view.
""" """
# The template needs the list of articles (for the JS part) # The template needs the list of articles (for the JS part)
articles = Article.objects.filter( articles = Article.objects.all()
Q(type_user="All") | Q(type_user=request.user.class_name)
)
# Building the invocie form and the article formset # Building the invocie form and the article formset
cost_estimate_form = CostEstimateForm(request.POST or None) cost_estimate_form = CostEstimateForm(request.POST or None)
@ -241,9 +239,7 @@ def new_custom_invoice(request):
point of view. point of view.
""" """
# The template needs the list of articles (for the JS part) # The template needs the list of articles (for the JS part)
articles = Article.objects.filter( articles = Article.objects.all()
Q(type_user="All") | Q(type_user=request.user.class_name)
)
# Building the invocie form and the article formset # Building the invocie form and the article formset
invoice_form = CustomInvoiceForm(request.POST or None) invoice_form = CustomInvoiceForm(request.POST or None)

View file

@ -283,8 +283,18 @@ class User(
return str(self.emailaddress_set.get(local_part=self.pseudo.lower())) return str(self.emailaddress_set.get(local_part=self.pseudo.lower()))
@cached_property @cached_property
def class_name(self): def class_type(self):
"""Renvoie si il s'agit d'un adhérent ou d'un club""" """Returns the type of that user; returns database keyname"""
if hasattr(self, "adherent"):
return "Adherent"
elif hasattr(self, "club"):
return "Club"
else:
raise NotImplementedError(_("Unknown type."))
@cached_property
def class_display(self):
"""Returns the typename of that user to display for user interface"""
if hasattr(self, "adherent"): if hasattr(self, "adherent"):
return _("Member") return _("Member")
elif hasattr(self, "club"): elif hasattr(self, "club"):