Changeset 1001
- Timestamp:
- 01/15/08 18:52:40 (1 year ago)
- Files:
-
- satchmo/trunk/satchmo/contact/forms.py (modified) (5 diffs)
- satchmo/trunk/satchmo/contact/models.py (modified) (2 diffs)
- satchmo/trunk/satchmo/contact/signals.py (modified) (1 diff)
- satchmo/trunk/satchmo/payment/common/forms.py (modified) (4 diffs)
- satchmo/trunk/satchmo/tax/templatetags/satchmo_tax.py (modified) (3 diffs)
- satchmo/trunk/satchmo/templates/shipping_options.html (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
satchmo/trunk/satchmo/contact/forms.py
r995 r1001 1 1 from django import newforms as forms 2 from django.dispatch import dispatcher 2 3 from django.utils.translation import ugettext as _ 3 4 from satchmo.configuration import config_value, config_get_group, SettingNotSet … … 5 6 from satchmo.l10n.models import Country 6 7 from satchmo.shop.models import Config 8 from signals import satchmo_contact_location_changed 7 9 import datetime 8 10 … … 158 160 bill_address = AddressBook(contact=customer) 159 161 162 changed_location = False 160 163 address_keys = bill_address.__dict__.keys() 161 164 for field in address_keys: 165 if (not changed_location) and field in ('state', 'country', 'city'): 166 if getattr(bill_address, field) != data[field]: 167 changed_location = True 162 168 try: 163 169 setattr(bill_address, field, data[field]) … … 184 190 185 191 for field in address_keys: 192 if (not changed_location) and field in ('state', 'country', 'city'): 193 if getattr(ship_address, field) != data[field]: 194 changed_location = True 186 195 try: 187 196 setattr(ship_address, field, data['ship_' + field]) … … 202 211 phone.save() 203 212 213 if changed_location: 214 dispatcher.send(signal=satchmo_contact_location_changed, contact=contact) 215 204 216 return customer.id 205 217 satchmo/trunk/satchmo/contact/models.py
r999 r1001 18 18 from satchmo.shop.templatetags.satchmo_currency import moneyfmt 19 19 from satchmo.shop.utils import load_module 20 from signals import order_success 20 from signals import order_success, satchmo_contact_location_changed 21 21 import config 22 22 import datetime … … 908 908 log.debug("caught cart changed signal - remove_order_on_cart_update") 909 909 Order.objects.remove_partial_order(request) 910 910 911 def _recalc_total_on_contact_change(contact=None): 912 #TODO: pull just the current order once we start using threadlocal middleware 913 log.debug("Recalculating all contact orders not in process") 914 orders = Order.objects.filter(contact=contact, status="") 915 log.debug("Found %i orders to recalc", orders.count()) 916 for order in orders: 917 order.copy_addresses() 918 order.recalculate_total() 919 911 920 dispatcher.connect(_remove_order_on_cart_update, signal=satchmo_cart_changed) 921 dispatcher.connect(_recalc_total_on_contact_change, signal=satchmo_contact_location_changed) satchmo/trunk/satchmo/contact/signals.py
r898 r1001 1 1 """Signals sent by the Cart system""" 2 order_success=object() 2 order_success = object() 3 satchmo_contact_location_changed = object() satchmo/trunk/satchmo/payment/common/forms.py
r988 r1001 1 1 from django import newforms as forms 2 2 from django.conf import settings 3 from django.template import Context3 from django.template import RequestContext 4 4 from django.template import loader 5 5 from django.utils.translation import ugettext as _ 6 from satchmo.configuration import config_value 6 7 from satchmo.contact.forms import ContactInfoForm 7 8 from satchmo.contact.models import Contact … … 16 17 import sys 17 18 18 def _get_shipping_choices( paymentmodule, cart, contact):19 def _get_shipping_choices(request, paymentmodule, cart, contact, default_view_tax=False): 19 20 """Iterate through legal shipping modules, building the list for display to the user. 20 21 … … 31 32 t = loader.get_template(template) 32 33 shipcost = method.cost() 33 c = Context({34 c = RequestContext(request, { 34 35 'amount': shipcost, 35 36 'description' : method.description(), 36 37 'method' : method.method(), 37 'expected_delivery' : method.expectedDelivery() }) 38 'expected_delivery' : method.expectedDelivery(), 39 'default_view_tax' : default_view_tax }) 38 40 shipping_options.append((method.id, t.render(c))) 39 41 shipping_dict[method.id] = shipcost … … 84 86 self.tempContact = None 85 87 86 shipping_choices, shipping_dict = _get_shipping_choices(paymentmodule, self.tempCart, self.tempContact) 88 if kwargs.has_key('default_view_tax'): 89 default_view_tax = kwargs['default_view_tax'] 90 else: 91 default_view_tax = config_value('TAX', 'DEFAULT_VIEW_TAX') 92 93 shipping_choices, shipping_dict = _get_shipping_choices(request, paymentmodule, self.tempCart, self.tempContact, default_view_tax=default_view_tax) 87 94 self.fields['shipping'].choices = shipping_choices 88 95 self.shipping_dict = shipping_dict satchmo/trunk/satchmo/tax/templatetags/satchmo_tax.py
r996 r1001 48 48 item = template.resolve_variable(self.cartitem, context) 49 49 except template.VariableDoesNotExist: 50 raise temp alte.TemplateSyntaxError("No such variable: %s", self.cartitem)50 raise template.TemplateSyntaxError("No such variable: %s", self.cartitem) 51 51 52 52 total = item.line_total + taxer.by_price(item.product.taxClass, item.line_total) 53 53 54 if self.currency: 54 55 return moneyfmt(total) … … 84 85 return moneyfmt(total) 85 86 86 if currency:87 return moneyfmt(total)88 87 return total 89 88 … … 146 145 147 146 return TaxRateNode(taxclass, order, digits) 147 148 class TaxedPriceNode(template.Node): 149 """Returns the taxed price for an amount. 150 """ 151 def __init__(self, price, currency, taxclass): 152 self.price = price 153 self.taxclass = taxclass 154 self.currency = currency 155 156 def render(self, context): 157 taxer = _get_taxprocessor(context['request']) 158 try: 159 price = template.resolve_variable(self.price, context) 160 except template.VariableDoesNotExist: 161 raise template.TemplateSyntaxError("No such variable: %s", self.price) 162 163 total = price + taxer.by_price(self.taxclass, price) 164 165 if self.currency: 166 return moneyfmt(total) 167 168 return total 169 170 def taxed_price(parser, token): 171 """Returns the taxed price for an amount. If currency evaluates true, 172 then return the total formatted through moneyfmt. 173 Example: {% taxed_price amount [currency] [taxclass] %} 174 """ 175 tokens = token.contents.split() 176 if len(tokens) < 2: 177 raise template.TemplateSyntaxError, "'%s' tag requires an amount argument" % tokens[0] 178 179 price = tokens[1] 180 if len(tokens) > 2: 181 currency = tokens[2] 182 else: 183 currency = False 184 185 if len(tokens) > 3: 186 taxclass = tokens[3] 187 else: 188 taxclass = "Default" 189 190 return TaxedPriceNode(price, currency, taxclass) 191 192 148 193 149 194 register.tag('cartitem_line_taxed_total', cartitem_line_taxed_total) 150 195 register.tag('cart_taxed_total', cart_taxed_total) 196 register.tag('taxed_price', taxed_price) 151 197 register.tag('tax_rate', tax_rate) satchmo/trunk/satchmo/templates/shipping_options.html
r727 r1001 1 1 {% load i18n %} 2 2 {% load satchmo_currency %} 3 4 {{amount|currency}} : {{ description }}<br> 3 {% if default_view_tax %}{% load satchmo_tax %}{% endif %} 4 {% if default_view_tax %}{% taxed_price amount 1 Shipping %}{% else %}{{amount|currency}}{% endif %} : {{ description }} 5 <br> 5 6 {% blocktrans %}Sent via {{ method }} arrives approximately {{ expected_delivery }}.{% endblocktrans %} 6 7 <hr>
