add ProductPrice

This commit is contained in:
Lance Edgar 2012-11-18 10:47:15 -08:00
parent 3e14d17ce5
commit 0f77c11a87
4 changed files with 113 additions and 3 deletions

View file

@ -72,4 +72,13 @@ admin.site.register(Category, ModelAdmin)
admin.site.register(Brand, ModelAdmin)
admin.site.register(Product, ModelAdmin)
class ProductPriceInline(admin.TabularInline):
model = ProductPrice
verbose_name_plural = "Prices"
exclude = ('uuid',)
extra = 0
class ProductAdmin(ModelAdmin):
inlines = [ProductPriceInline]
admin.site.register(Product, ProductAdmin)

View file

@ -86,8 +86,26 @@ class Migration(SchemaMigration):
))
db.send_create_signal('rattail', ['Product'])
# Adding model 'ProductPrice'
db.create_table('rattail_product_prices', (
('uuid', self.gf('rattail.django.rattail.models.core.UUIDField')(max_length=32, primary_key=True)),
('product', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['rattail.Product'], db_column='product_uuid')),
('type', self.gf('django.db.models.fields.IntegerField')(null=True, blank=True)),
('level', self.gf('django.db.models.fields.IntegerField')(null=True, blank=True)),
('starts', self.gf('django.db.models.fields.DateTimeField')(null=True, blank=True)),
('ends', self.gf('django.db.models.fields.DateTimeField')(null=True, blank=True)),
('price', self.gf('django.db.models.fields.DecimalField')(null=True, max_digits=8, decimal_places=3, blank=True)),
('multiple', self.gf('django.db.models.fields.IntegerField')(null=True, blank=True)),
('pack_price', self.gf('django.db.models.fields.DecimalField')(null=True, max_digits=8, decimal_places=3, blank=True)),
('pack_multiple', self.gf('django.db.models.fields.IntegerField')(null=True, blank=True)),
))
db.send_create_signal('rattail', ['ProductPrice'])
def backwards(self, orm):
# Deleting model 'ProductPrice'
db.delete_table('rattail_product_prices')
# Deleting model 'Product'
db.delete_table('rattail_products')
@ -176,6 +194,19 @@ class Migration(SchemaMigration):
'upc': ('rattail.django.rattail.models.rattail.GPCField', [], {'db_index': 'True'}),
'uuid': ('rattail.django.rattail.models.core.UUIDField', [], {'max_length': '32', 'primary_key': 'True'})
},
'rattail.productprice': {
'Meta': {'object_name': 'ProductPrice', 'db_table': "'rattail_product_prices'"},
'ends': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
'level': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
'multiple': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
'pack_multiple': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
'pack_price': ('django.db.models.fields.DecimalField', [], {'null': 'True', 'max_digits': '8', 'decimal_places': '3', 'blank': 'True'}),
'price': ('django.db.models.fields.DecimalField', [], {'null': 'True', 'max_digits': '8', 'decimal_places': '3', 'blank': 'True'}),
'product': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['rattail.Product']", 'db_column': "'product_uuid'"}),
'starts': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
'type': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
'uuid': ('rattail.django.rattail.models.core.UUIDField', [], {'max_length': '32', 'primary_key': 'True'})
},
}
complete_apps = ['rattail']

View file

@ -30,15 +30,17 @@ from __future__ import absolute_import
from django.db import models
import rattail
from rattail.gpc import GPC
from rattail.django.rattail.models import Model, uuid_field
from rattail.django.rattail.models.contact import (
ContactInfoManager, PhoneNumber, EmailAddress)
from rattail.django.util import enum_to_choices
__all__ = ['Store', 'StorePhoneNumber', 'StoreEmailAddress',
'Department', 'Subdepartment', 'Category',
'Brand', 'Product']
'Department', 'Subdepartment', 'Category', 'Brand',
'Product', 'ProductPrice']
class GPCField(models.BigIntegerField):
@ -210,3 +212,32 @@ class Product(Model):
def __unicode__(self):
return unicode(self.description or '')
class ProductPrice(Model):
"""
Represents a price for a product.
"""
class Meta(Model.Meta):
db_table = Model.prefix('product_prices')
PRICE_TYPE_CHOICES = enum_to_choices(rattail.PRICE_TYPE)
uuid = uuid_field()
product = models.ForeignKey(Product, db_column='product_uuid')
type = models.IntegerField(choices=PRICE_TYPE_CHOICES, blank=True, null=True)
level = models.IntegerField(blank=True, null=True)
starts = models.DateTimeField(blank=True, null=True)
ends = models.DateTimeField(blank=True, null=True)
price = models.DecimalField(max_digits=8, decimal_places=3, blank=True, null=True)
multiple = models.IntegerField(blank=True, null=True)
pack_price = models.DecimalField(max_digits=8, decimal_places=3, blank=True, null=True)
pack_multiple = models.IntegerField(blank=True, null=True)
def __repr__(self):
return "<ProductPrice: %s : %s>" % (self.product, self.price)
def __unicode__(self):
type = rattail.PRICE_TYPE.get(self.type, "?")
return u'$ %0.2f / %d (%s)' % (self.price, self.multiple or 1, type)

39
rattail/django/util.py Normal file
View file

@ -0,0 +1,39 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
################################################################################
#
# Rattail -- Retail Software Framework
# Copyright © 2010-2012 Lance Edgar
#
# This file is part of Rattail.
#
# Rattail is free software: you can redistribute it and/or modify it under the
# terms of the GNU Affero General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option)
# any later version.
#
# Rattail is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
# more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with Rattail. If not, see <http://www.gnu.org/licenses/>.
#
################################################################################
"""
``rattail.django.util`` -- Utilities
"""
def enum_to_choices(enum):
"""
Convert ``enum`` (which should be an enumeration as is normally used by
Rattail) into a "choices" tuple as is normally used by Django.
"""
choices = []
for key, value in enum.iteritems():
choices.append((key, value))
return tuple(choices)