Commits

Ian George committed 0f7bac5

changed payment_made code because the order should be created when the payment is made and the post_update signal recalculates the total

  • Participants
  • Parent commits 5f58e0f

Comments (0)

Files changed (2)

File quiet/shop/migrations/0004_add_model_ShippingItem.py

+# encoding: utf-8
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+class Migration(SchemaMigration):
+
+    def forwards(self, orm):
+        
+        # Adding model 'ShippingItem'
+        db.create_table('shop_shippingitem', (
+            ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+            ('basket', self.gf('django.db.models.fields.related.ForeignKey')(related_name='shipping_items', to=orm['shop.Basket'])),
+            ('basket_item', self.gf('django.db.models.fields.related.OneToOneField')(blank=True, related_name='shipping_item', unique=True, null=True, to=orm['shop.BasketItem'])),
+            ('item_content_type', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['contenttypes.ContentType'])),
+            ('item_object_id', self.gf('django.db.models.fields.PositiveIntegerField')()),
+            ('tax', self.gf('django.db.models.fields.DecimalField')(default=0, null=True, max_digits=8, decimal_places=2, blank=True)),
+            ('price', self.gf('django.db.models.fields.DecimalField')(null=True, max_digits=8, decimal_places=2)),
+        ))
+        db.send_create_signal('shop', ['ShippingItem'])
+
+
+    def backwards(self, orm):
+        
+        # Deleting model 'ShippingItem'
+        db.delete_table('shop_shippingitem')
+
+
+    models = {
+        'contenttypes.contenttype': {
+            'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
+            'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
+        },
+        'shop.basket': {
+            'Meta': {'object_name': 'Basket'},
+            'checked_out': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
+        },
+        'shop.basketitem': {
+            'Meta': {'unique_together': "(('basket', 'item_object_id', 'item_content_type'),)", 'object_name': 'BasketItem'},
+            'basket': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'items'", 'to': "orm['shop.Basket']"}),
+            'deposit': ('django.db.models.fields.DecimalField', [], {'null': 'True', 'max_digits': '8', 'decimal_places': '2', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'item_content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
+            'item_object_id': ('django.db.models.fields.PositiveIntegerField', [], {}),
+            'item_type': ('django.db.models.fields.IntegerField', [], {}),
+            'price': ('django.db.models.fields.DecimalField', [], {'null': 'True', 'max_digits': '8', 'decimal_places': '2'}),
+            'quantity': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
+            'tax': ('django.db.models.fields.DecimalField', [], {'default': '0', 'null': 'True', 'max_digits': '8', 'decimal_places': '2', 'blank': 'True'})
+        },
+        'shop.order': {
+            'Meta': {'ordering': "['-date']", 'object_name': 'Order'},
+            'balance': ('django.db.models.fields.DecimalField', [], {'null': 'True', 'max_digits': '8', 'decimal_places': '2', 'blank': 'True'}),
+            'complete': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'date': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+            'deposit': ('django.db.models.fields.DecimalField', [], {'null': 'True', 'max_digits': '8', 'decimal_places': '2', 'blank': 'True'}),
+            'discount': ('django.db.models.fields.DecimalField', [], {'null': 'True', 'max_digits': '8', 'decimal_places': '2', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'order_ref': ('django.db.models.fields.CharField', [], {'max_length': '30', 'null': 'True'}),
+            'shipping': ('django.db.models.fields.DecimalField', [], {'null': 'True', 'max_digits': '8', 'decimal_places': '2'}),
+            'subtotal': ('django.db.models.fields.DecimalField', [], {'null': 'True', 'max_digits': '8', 'decimal_places': '2'}),
+            'tax': ('django.db.models.fields.DecimalField', [], {'null': 'True', 'max_digits': '8', 'decimal_places': '2', 'blank': 'True'}),
+            'tax_rate': ('django.db.models.fields.DecimalField', [], {'max_digits': '8', 'decimal_places': '2'}),
+            'total': ('django.db.models.fields.DecimalField', [], {'null': 'True', 'max_digits': '8', 'decimal_places': '2'})
+        },
+        'shop.orderaddress': {
+            'Meta': {'object_name': 'OrderAddress'},
+            'address1': ('django.db.models.fields.CharField', [], {'max_length': '50'}),
+            'address2': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
+            'address3': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
+            'city': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+            'country': ('django.db.models.fields.CharField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}),
+            'county': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
+            'email': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '50'}),
+            'order': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'addresses'", 'to': "orm['shop.Order']"}),
+            'postcode': ('django.db.models.fields.CharField', [], {'max_length': '50', 'blank': 'True'}),
+            'telephone': ('django.db.models.fields.CharField', [], {'max_length': '40', 'blank': 'True'}),
+            'type': ('django.db.models.fields.CharField', [], {'max_length': '10'})
+        },
+        'shop.orderitem': {
+            'Meta': {'object_name': 'OrderItem'},
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'order': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'items'", 'to': "orm['shop.Order']"}),
+            'price': ('django.db.models.fields.DecimalField', [], {'max_digits': '8', 'decimal_places': '2'}),
+            'product_content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
+            'product_object_id': ('django.db.models.fields.PositiveIntegerField', [], {}),
+            'qty': ('django.db.models.fields.IntegerField', [], {}),
+            'tax': ('django.db.models.fields.DecimalField', [], {'null': 'True', 'max_digits': '8', 'decimal_places': '2', 'blank': 'True'}),
+            'total': ('django.db.models.fields.DecimalField', [], {'max_digits': '8', 'decimal_places': '2'})
+        },
+        'shop.orderpayment': {
+            'Meta': {'ordering': "['-date']", 'object_name': 'OrderPayment'},
+            'amount': ('django.db.models.fields.DecimalField', [], {'max_digits': '8', 'decimal_places': '2'}),
+            'date': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'order': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'payments'", 'to': "orm['shop.Order']"}),
+            'reference': ('django.db.models.fields.CharField', [], {'max_length': '50'}),
+            'source': ('django.db.models.fields.CharField', [], {'max_length': '20'}),
+            'tax': ('django.db.models.fields.DecimalField', [], {'null': 'True', 'max_digits': '8', 'decimal_places': '2', 'blank': 'True'})
+        },
+        'shop.orderstatus': {
+            'Meta': {'ordering': "['-date']", 'object_name': 'OrderStatus'},
+            'comments': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+            'date': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'order': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'status'", 'to': "orm['shop.Order']"}),
+            'status': ('django.db.models.fields.CharField', [], {'max_length': '10'})
+        },
+        'shop.shippingitem': {
+            'Meta': {'unique_together': "(('basket', 'item_object_id', 'item_content_type'),)", 'object_name': 'ShippingItem'},
+            'basket': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'shipping_items'", 'to': "orm['shop.Basket']"}),
+            'basket_item': ('django.db.models.fields.related.OneToOneField', [], {'blank': 'True', 'related_name': "'shipping_item'", 'unique': 'True', 'null': 'True', 'to': "orm['shop.BasketItem']"}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'item_content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
+            'item_object_id': ('django.db.models.fields.PositiveIntegerField', [], {}),
+            'price': ('django.db.models.fields.DecimalField', [], {'null': 'True', 'max_digits': '8', 'decimal_places': '2'}),
+            'tax': ('django.db.models.fields.DecimalField', [], {'default': '0', 'null': 'True', 'max_digits': '8', 'decimal_places': '2', 'blank': 'True'})
+        }
+    }
+
+    complete_apps = ['shop']

File quiet/shop/models/order.py

         status = OrderStatus(order=ordr, status='new', comments='Order complete and ready for processing')
         status.save()
 
-    if not ordr.balance:
-        ordr.balance = Decimal(0)
-
-    for payment in ordr.payments.all():
-        if payment.amount:
-            ordr.balance -= payment.amount
+    #if not ordr.balance:
+    #    ordr.balance = Decimal(0)
+    #    for payment in ordr.payments.all():
+    #        if payment.amount:
+    #            ordr.balance -= payment.amount
     ordr.complete = True
     ordr.save()