Commit 76972e66 authored by ljf's avatar ljf
Browse files

[enh] Link ip pools to an offer

parent 67c9e07f
......@@ -4,7 +4,7 @@ from __future__ import unicode_literals
from django.contrib import admin
from polymorphic.admin import PolymorphicChildModelAdmin
from coin.offers.models import Offer, OfferSubscription
from coin.offers.models import Offer, OfferIPPool, OfferSubscription
from coin.offers.offersubscription_filter import\
OfferSubscriptionTerminationFilter,\
OfferSubscriptionCommitmentFilter
......@@ -12,6 +12,11 @@ from coin.offers.forms import OfferAdminForm
import autocomplete_light
class OfferIPPoolAdmin(admin.TabularInline):
model = OfferIPPool
extra = 1
class OfferAdmin(admin.ModelAdmin):
list_display = ('get_configuration_type_display', 'name', 'reference', 'billing_period', 'period_fees',
'initial_fees')
......@@ -19,7 +24,7 @@ class OfferAdmin(admin.ModelAdmin):
list_filter = ('configuration_type',)
search_fields = ['name']
form = OfferAdminForm
inlines = (OfferIPPoolAdmin,)
# def get_readonly_fields(self, request, obj=None):
# if obj:
# return ['backend',]
......@@ -36,7 +41,7 @@ class OfferSubscriptionAdmin(admin.ModelAdmin):
'offer', 'member')
search_fields = ['member__first_name', 'member__last_name', 'member__email',
'member__nickname']
fields = (
'member',
'offer',
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('resources', '0003_auto_20150203_1043'),
('offers', '0007_offersubscription_comments'),
]
operations = [
migrations.CreateModel(
name='OfferIPPool',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('priority', models.IntegerField()),
('ippool', models.ForeignKey(to='resources.IPPool')),
('offer', models.ForeignKey(to='offers.Offer')),
],
options={
'ordering': ['priority'],
},
),
migrations.AddField(
model_name='offer',
name='ippools',
field=models.ManyToManyField(to='resources.IPPool', through='offers.OfferIPPool'),
),
]
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('offers', '0008_auto_20170818_1507'),
]
operations = [
migrations.AlterModelOptions(
name='offerippool',
options={'ordering': ['to_assign'], 'verbose_name': "pool d'IP", 'verbose_name_plural': "pools d'IP"},
),
migrations.RemoveField(
model_name='offerippool',
name='priority',
),
migrations.AddField(
model_name='offerippool',
name='to_assign',
field=models.BooleanField(default=False, verbose_name='assignation par d\xe9faut'),
),
migrations.AlterField(
model_name='offerippool',
name='ippool',
field=models.ForeignKey(verbose_name="pool d'IP", to='resources.IPPool'),
),
migrations.AlterField(
model_name='offerippool',
name='offer',
field=models.ForeignKey(verbose_name='offre', to='offers.Offer'),
),
]
......@@ -8,6 +8,8 @@ from django.db import models
from django.db.models import Count, Q
from django.core.validators import MinValueValidator
from coin.resources.models import IPPool
class Offer(models.Model):
"""Description of an offer available to subscribers.
......@@ -44,6 +46,8 @@ class Offer(models.Model):
verbose_name='n\'est pas facturable',
help_text='L\'offre ne sera pas facturée par la commande charge_members')
ippools = models.ManyToManyField(IPPool, through='OfferIPPool')
def get_configuration_type_display(self):
"""
Renvoi le nom affichable du type de configuration
......@@ -79,6 +83,20 @@ class Offer(models.Model):
verbose_name = 'offre'
class OfferIPPool(models.Model):
offer = models.ForeignKey(Offer,
verbose_name='offre')
ippool = models.ForeignKey(IPPool,
verbose_name='pool d\'IP')
to_assign = models.BooleanField(default=False,
verbose_name='assignation par défaut')
class Meta:
verbose_name = 'pool d\'IP'
verbose_name_plural = "pools d'IP"
ordering = ['-to_assign']
class OfferSubscriptionQuerySet(models.QuerySet):
def running(self, at_date=None):
""" Only the running contracts at a given date.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment