From c7c1897b38ce1d58f25513bd83579ccd27d49fda Mon Sep 17 00:00:00 2001 From: Krzysztof Dorosz Date: Thu, 1 Jan 2015 13:02:52 +0100 Subject: [PATCH] Refactoring of settings variable names --- CHANGELOG | 25 ++++++++++- conftest.py | 12 ++--- demo/example/settings.py | 12 ++--- docs/source/invoicing.rst | 8 ++-- docs/source/plans.rst | 2 +- docs/source/plans_change.rst | 2 +- docs/source/quota_validators.rst | 8 ++-- docs/source/settings.rst | 76 ++++++++++++++++---------------- docs/source/taxation.rst | 4 +- plans/conf.py | 9 ++-- plans/models.py | 20 ++++----- plans/tasks.py | 2 +- plans/taxation/__init__.py | 8 ++-- plans/taxation/ru.py | 4 +- plans/tests/tests.py | 62 +++++++++++++------------- plans/validators.py | 2 +- plans/views.py | 27 ++++++------ 17 files changed, 151 insertions(+), 132 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 1aac3963..3a215470 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,8 +1,29 @@ django-plans changelog ====================== -current dev ------------ +0.7 +--- +* Changes in plans.taxation.eu.EUTaxationPolicy to implement new EU VAT regulations (MOSS) +* Clean up settings variables naming conventions prepending PLANS_ prefix: + * Renamed settings variable name TAXATION_POLICY to PLANS_TAXATION_POLICY + * Renamed settings variable name ISSUER_DATA to PLANS_INVOICE_ISSUER + * Renamed settings variable name PLAN_EXPIRATION_REMIND to PLANS_EXPIRATION_REMIND + * Renamed settings variable name PLAN_CHANGE_POLICY to PLANS_CHANGE_POLICY + * Renamed settings variable name PLAN_VALIDATORS to PLANS_VALIDATORS + * Renamed settings variable name CURRENCY to PLANS_CURRENCY + * Renamed settings variable name TAX to PLANS_TAX + * Renamed settings variable name TAX_COUNTRY to PLANS_TAX_COUNTRY + * Renamed settings variable name INVOICE_LOGO_URL to PLANS_INVOICE_LOGO_URL + * Renamed settings variable name INVOICE_NUMBER_FORMAT to PLANS_INVOICE_NUMBER_FORMAT + * Renamed settings variable name INVOICE_TEMPLATE to PLANS_INVOICE_TEMPLATE + * Renamed settings variable name INVOICE_COUNTER_RESET to PLANS_INVOICE_COUNTER_RESET + * Renamed settings variable name ORDER_EXPIRATION to PLANS_ORDER_EXPIRATION + * Renamed settings variable name PLAN_DEFAULT_GRACE_PERIOD to PLANS_DEFAULT_GRACE_PERIOD + + + +0.6+ +---- * Changing `QuotaValidator` API. `ModelCountValidator` requires now to give `add` argument only as a kwarg. * Adding support for defining URL for plan, quota and pricing period that will act as a clickable pricing table header (requires schema migration) diff --git a/conftest.py b/conftest.py index d4ce6c86..4b8b382d 100644 --- a/conftest.py +++ b/conftest.py @@ -35,7 +35,7 @@ def pytest_configure(config): TEMPLATE_DEBUG=True, USE_TZ=True, ALLOWED_HOSTS=['*'], - ISSUER_DATA={ + PLANS_INVOICE_ISSUER={ "issuer_name": "My Company Ltd", "issuer_street": "48th Suny street", "issuer_zipcode": "111-456", @@ -43,11 +43,11 @@ def pytest_configure(config): "issuer_country": "PL", "issuer_tax_number": "PL123456789", }, - TAX=Decimal(23.0), - TAXATION_POLICY='plans.locale.eu.taxation.EUTaxationPolicy', - TAX_COUNTRY='PL', - CURRENCY='PLN', - PLAN_VALIDATORS={ + PLANS_TAX=Decimal(23.0), + PLANS_TAXATION_POLICY='plans.taxation.eu.EUTaxationPolicy', + PLANS_TAX_COUNTRY='PL', + PLANS_CURRENCY='PLN', + PLANS_VALIDATORS={ 'MAX_FOO_COUNT': 'example.foo.validators.max_foos_validator', }, EMAIL_BACKEND='django.core.mail.backends.console.EmailBackend', diff --git a/demo/example/settings.py b/demo/example/settings.py index 8b7e9b28..4f3a0d2c 100644 --- a/demo/example/settings.py +++ b/demo/example/settings.py @@ -131,7 +131,7 @@ ('en', 'English'), ) -ISSUER_DATA = { +PLANS_INVOICE_ISSUER = { "issuer_name": "My Company Ltd", "issuer_street": "48th Suny street", "issuer_zipcode": "111-456", @@ -140,15 +140,15 @@ "issuer_tax_number": "PL123456789", } -TAX = Decimal('23.0') -TAXATION_POLICY = 'plans.taxation.eu.EUTaxationPolicy' -TAX_COUNTRY = 'PL' +PLANS_TAX = Decimal('23.0') +PLANS_TAXATION_POLICY = 'plans.taxation.eu.EUTaxationPolicy' +PLANS_TAX_COUNTRY = 'PL' -PLAN_VALIDATORS = { +PLANS_VALIDATORS = { 'MAX_FOO_COUNT': 'example.foo.validators.max_foos_validator', } -CURRENCY = 'EUR' +PLANS_CURRENCY = 'EUR' EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' diff --git a/docs/source/invoicing.rst b/docs/source/invoicing.rst index 35030bd9..ffd873e2 100644 --- a/docs/source/invoicing.rst +++ b/docs/source/invoicing.rst @@ -7,8 +7,8 @@ There is a built in support for creating invoices. This functionality brings pow * invoices can be marked as "requiring shipment" * invoices can be previewed as HTML or PDF -Changing values of VAT tax and ISSUER_DATA in a living system -------------------------------------------------------------- +Changing values of VAT tax and PLANS_INVOICE_ISSUER in a living system +---------------------------------------------------------------------- Your system can be running for a while. You can have a multiple orders and you could have issued a multiple invoices already. There can be a situation that you need to change after a while a tax @@ -24,8 +24,8 @@ After changing those settings every new order, payment, invoice will use those n all your already created orders but not yet paid will have old tax. If this is what you don't want you need to cancel those orders manually and remember to contact your client that theirs orders were cancelled! - This however is not a case with ``ISSUER_DATA`` change, because those data are taken in the same moment - of issuing invoice. Even an old order will use new ``ISSUER_DATA`` when invoicing a new payment. + This however is not a case with ``PLANS_INVOICE_ISSUER`` change, because those data are taken in the same moment + of issuing invoice. Even an old order will use new ``PLANS_INVOICE_ISSUER`` when invoicing a new payment. Billing data ------------ diff --git a/docs/source/plans.rst b/docs/source/plans.rst index b7bd6bd3..ccb9bc28 100644 --- a/docs/source/plans.rst +++ b/docs/source/plans.rst @@ -81,7 +81,7 @@ List of ``pricing`` periods **type**: Many-to-many with ``Pricing`` by ``PlanPricing`` Many pricing periods can be defined for a given plan. For each entry there is a need of defining price. The currency -of price is defined by ``settings.CURRENCY``. +of price is defined by ``settings.PLANS_CURRENCY``. .. warning:: diff --git a/docs/source/plans_change.rst b/docs/source/plans_change.rst index 2e807e2e..8d6980ef 100644 --- a/docs/source/plans_change.rst +++ b/docs/source/plans_change.rst @@ -2,7 +2,7 @@ Plan change policies ==================== Changing (upgrading or downgrading) plan is another thing that can be highly customizable. You can choose which -ChangePlanPolicy should be used via ``PLAN_CHANGE_POLICY`` settings variable. +ChangePlanPolicy should be used via ``PLANS_CHANGE_POLICY`` settings variable. Plan change policy is a class that derives from ``plans.plan_change.PlanChangePolicy`` which should implement ``get_change_price(plan_old, plan_new, period)``. This method returns should return total price of changing current plan to new one, assuming that a given active period left on the account. diff --git a/docs/source/quota_validators.rst b/docs/source/quota_validators.rst index 4f4c11cc..51bf853d 100644 --- a/docs/source/quota_validators.rst +++ b/docs/source/quota_validators.rst @@ -27,11 +27,11 @@ Account complete validation Complete account validation is needed when user is switching a plan (or in a general - activating a plan). The reason is that user account can be in the state that exhausting limits of new plan (e.g. on downgrade). Plan should not be activated on the user account until user will not remove over limit resources until the account could validate in limits of the new plan. -In django-plans there is a common validation mechanism which requires defining ``PLAN_VALIDATORS`` variable in ``settings.py``. +In django-plans there is a common validation mechanism which requires defining ``PLANS_VALIDATORS`` variable in ``settings.py``. -The format of ``PLAN_VALIDATORS`` variable is given as a dict:: +The format of ``PLANS_VALIDATORS`` variable is given as a dict:: - PLAN_VALIDATORS = { + PLANS_VALIDATORS = { '' : '', [...] } @@ -40,7 +40,7 @@ First of all this variable defines all quota that should be validated on any pla .. note:: - Please note that the only quota that can be added to ``PLAN_VALIDATORS`` are "limiting resources quota" and "limiting states" quota. Those are the kind of quota that conceptually can be validated within the database state. The third kind of quota ("limiting actions quota") are to be checked on to go when user is just using it's account and performing certain actions. + Please note that the only quota that can be added to ``PLANS_VALIDATORS`` are "limiting resources quota" and "limiting states" quota. Those are the kind of quota that conceptually can be validated within the database state. The third kind of quota ("limiting actions quota") are to be checked on to go when user is just using it's account and performing certain actions. Secondly each quota has a specific validator defined that is custom to your need of validations. diff --git a/docs/source/settings.rst b/docs/source/settings.rst index 5f57345a..f4314e6e 100644 --- a/docs/source/settings.rst +++ b/docs/source/settings.rst @@ -2,7 +2,7 @@ Configuration via `settings` ============================ -``CURRENCY`` +``PLANS_CURRENCY`` ------------ **Required** @@ -11,7 +11,7 @@ Three letter code for system currency. Should always be capitalized. Example:: - CURRENCY = 'EUR' + PLANS_CURRENCY = 'EUR' ``DEFAULT_FROM_EMAIL`` @@ -21,7 +21,7 @@ Example:: This is the default mail ``FROM`` value for sending system notifications. -``INVOICE_COUNTER_RESET`` +``PLANS_INVOICE_COUNTER_RESET`` ------------------------- **Optional** @@ -29,24 +29,24 @@ This is the default mail ``FROM`` value for sending system notifications. Default: ``monthly`` This settings switches invoice counting per days, month or year basis. It requires to -provide one of following string format: +provide one of the value: - * ``daily`` - * ``monthly`` - * ``annually`` + * Invoice.NUMBERING.DAILY + * Invoice.NUMBERING.MONTHLY + * Invoice.NUMBERING.ANNUALY Example:: - INVOICE_COUNTER_RESET = 'yearly' + PLANS_INVOICE_COUNTER_RESET = Invoice.NUMBERING.MONTHLY .. warning:: - Remember to set ``INVOICE_NUMBER_FORMAT`` manually to match preferred way of invoice numbering schema. For example if - you choose reset counter on daily basis, you need to use in ``INVOICE_NUMBER_FORMAT`` at least ``{{ invoice.issued|date:'d/m/Y' }}`` + Remember to set ``PLANS_INVOICE_NUMBER_FORMAT`` manually to match preferred way of invoice numbering schema. For example if + you choose reset counter on daily basis, you need to use in ``PLANS_INVOICE_NUMBER_FORMAT`` at least ``{{ invoice.issued|date:'d/m/Y' }}`` to distinguish invoice's full numbers between days. -``INVOICE_NUMBER_FORMAT`` +``PLANS_INVOICE_NUMBER_FORMAT`` ------------------------- **Optional** @@ -59,7 +59,7 @@ A django template syntax format for rendering invoice full number. Within this t Example:: - INVOICE_NUMBER_FROMAT = "{{ invoice.number }}/{{ invoice.issued|date='m/FV/Y' }}" + PLANS_INVOICE_NUMBER_FORMAT = "{{ invoice.number }}/{{ invoice.issued|date='m/FV/Y' }}" This example for invoice issued on ``March 5th, 2010``, with sequential number ``13``, will produce the full number ``13/03/FV/2010`` or ``13/03/PF/2010`` based on invoice type. @@ -68,7 +68,7 @@ This example for invoice issued on ``March 5th, 2010``, with sequential number ` Full number of an invoice is saved with the Invoice object. Changing this value in settings will affect only newly created invoices. -``INVOICE_LOGO_URL`` +``PLANS_INVOICE_LOGO_URL`` -------------------- **Optional** @@ -81,13 +81,13 @@ URL of logo image that should be placed in an invoice. It will be available in i Example:: from urllib.parse import urljoin - INVOICE_LOGO_URL = urljoin(STATIC_URL, 'my_logo.png') + PLANS_INVOICE_LOGO_URL = urljoin(STATIC_URL, 'my_logo.png') -``INVOICE_TEMPLATE`` +``PLANS_INVOICE_TEMPLATE`` -------------------- **Optional** @@ -105,12 +105,12 @@ Template name for displaying invoice. Example:: - INVOICE_TEMPLATE = 'plans/invoices/PL_EN.html' + PLANS_INVOICE_TEMPLATE = 'plans/invoices/PL_EN.html' -``ISSUER_DATA`` +``PLANS_INVOICE_ISSUER`` --------------- **Required** @@ -118,7 +118,7 @@ You need to define a dictionary that will store information needed to issue an i Example:: - ISSUER_DATA = { + PLANS_INVOICE_ISSUER = { "issuer_name": "Joe Doe Company", "issuer_street": "Django street, 34", "issuer_zipcode": "123-3444", @@ -131,7 +131,7 @@ Example:: -``ORDER_EXPIRATION`` +``PLANS_ORDER_EXPIRATION`` -------------------- **Optional** @@ -139,15 +139,15 @@ Example:: Default: ``14`` -A number of days that an Order is valid (e.g. to start a payment) counting from order creation date. This value is only used in ``is_ready_for_payment()`` method for django-getpaid integration. This value has no effect on processing already paid orders before ``ORDER_EXPIRATION`` period, even if confirmation for this payment will came after ``ORDER_EXPIRATION`` period. +A number of days that an Order is valid (e.g. to start a payment) counting from order creation date. This value is only used in ``is_ready_for_payment()`` method for django-getpaid integration. This value has no effect on processing already paid orders before ``PLANS_ORDER_EXPIRATION`` period, even if confirmation for this payment will came after ``PLANS_ORDER_EXPIRATION`` period. Example:: - ORDER_EXPIRATION = 14 + PLANS_ORDER_EXPIRATION = 14 -``PLAN_EXPIRATION_REMIND`` --------------------------- +``PLANS_EXPIRATION_REMIND`` +--------------------------- **Optional** @@ -159,13 +159,13 @@ Default: ``[]`` Example:: - PLAN_EXPIRATION_REMIND = [1, 3 , 7] + PLANS_EXPIRATION_REMIND = [1, 3 , 7] User will receive notification before 7 , 3 and 1 day to account expire. -``PLAN_CHANGE_POLICY`` +``PLANS_CHANGE_POLICY`` ---------------------- **Optional** @@ -174,7 +174,7 @@ Default: ``'plans.plan_change.StandardPlanChangePolicy'`` A full python to path that should be used as plan change policy. -``PLAN_DEFAULT_GRACE_PERIOD`` +``PLANS_DEFAULT_GRACE_PERIOD`` ----------------------------- **Optional** @@ -187,7 +187,7 @@ New account default plan expiration period counted in days. Example:: - PLAN_DEFAULT_GRACE_PERIOD = 30 + PLANS_DEFAULT_GRACE_PERIOD = 30 @@ -197,7 +197,7 @@ Example:: -``PLAN_VALIDATORS`` +``PLANS_VALIDATORS`` ------------------------------ **Optional** @@ -212,7 +212,7 @@ Given account will be activated only if calling all validators that are defined Example:: - PLAN_VALIDATORS = { + PLANS_VALIDATORS = { 'CAN_DO_SOMETHING' : 'myproject.validators.can_do_something_validator', 'MAX_STORAGE' : 'myproject.validators.max_storage_validator', } @@ -229,28 +229,28 @@ Default: ``True`` Boolean value for enabling (default) or disabling the sending of plan related emails. -``TAX`` +``PLANS_TAX`` ------- **Required** -Decimal or integer value for default TAX. +Decimal or integer value for default TAX (usually referred as VAT). Example:: from decimal import Decimal - TAX = Decimal(23.0) #for 23% VAT + PLANS_TAX = Decimal('23.0') # for 23% VAT Default: ``None`` .. warning:: - The value ``None`` means "TAX not applicable, rather than value ``Decimal(0)`` which means 0% TAX. + The value ``None`` means "TAX not applicable, rather than value ``Decimal('0')`` which is 0% TAX. .. _settings-TAXATION_POLICY: -``TAXATION_POLICY`` +``PLANS_TAXATION_POLICY`` ------------------- **Required** @@ -259,12 +259,12 @@ Class that realises taxation of an order. Example:: - TAXATION_POLICY='plans.locale.eu.taxation.EUTaxationPolicy' + PLANS_TAXATION_POLICY='plans.taxation.eu.EUTaxationPolicy' Further reading: :doc:`taxation` -``TAX_COUNTRY`` +``PLANS_TAX_COUNTRY`` --------------- **Optional** @@ -273,10 +273,10 @@ Two letter ISO country code. This variable is used to determine origin issuers c Example:: - TAX_COUNTRY = 'PL' + PLANS_TAX_COUNTRY = 'PL' .. note:: - ``settings.TAX_COUNTRY`` is a separate value from ``settings.ISSUER_DATA.issuer_country`` on purpose. ``ISSUER_DATA`` is just what you want to have printed on an invoice. \ No newline at end of file + ``settings.PLANS_TAX_COUNTRY`` is a separate value from ``settings.PLANS_INVOICE_ISSUER.issuer_country`` on purpose. ``PLANS_INVOICE_ISSUER`` is just what you want to have printed on an invoice. \ No newline at end of file diff --git a/docs/source/taxation.rst b/docs/source/taxation.rst index f5727ac4..e66eac45 100644 --- a/docs/source/taxation.rst +++ b/docs/source/taxation.rst @@ -11,7 +11,7 @@ Taxation policy can be defined as a simple class that should inherit from ``plan :members: :undoc-members: -Django-plans application is shipped with some default taxation policies. You can choose them via :ref:`settings-TAXATION_POLICY` variable. +Django-plans application is shipped with some default taxation policies. You can choose them via :ref:`settings-PLANS_TAXATION_POLICY` variable. ``EUTaxationPolicy`` -------------------- @@ -22,7 +22,7 @@ Django-plans application is shipped with some default taxation policies. You can .. note:: - This taxation policy requires ``suds`` and ``vatnumber`` python modules (connecting to `VIES `_). If you want them automatically installed please remember to insert extra depedencies for pip:: + This taxation policy requires ``suds`` (we use suds-jurko) and ``vatnumber`` python modules (connecting to `VIES `_). If you want them automatically installed please remember to insert extra depedencies for pip:: $ pip install django-plans[eu] diff --git a/plans/conf.py b/plans/conf.py index ef546e9a..8cc5e96c 100644 --- a/plans/conf.py +++ b/plans/conf.py @@ -1,8 +1,7 @@ - # TODO use django-conf from django.conf import settings -TAX = getattr(settings, 'PLANS_TAX', None) -TAXATION_POLICY = getattr(settings, - 'PLANS_TAXATION_POLICY', - 'plans.taxation.TAXATION_POLICY') +TAX = getattr(settings, 'PLANS_TAX', None) +TAXATION_POLICY = getattr(settings, + 'PLANS_TAXATION_POLICY', + 'plans.taxation.TAXATION_POLICY') diff --git a/plans/models.py b/plans/models.py index ac7856d7..594d1c2c 100644 --- a/plans/models.py +++ b/plans/models.py @@ -193,7 +193,7 @@ def initialize(self): if not self.is_active(): if self.expire is None: self.expire = now() + timedelta( - days=getattr(settings, 'PLAN_DEFAULT_GRACE_PERIOD', 30)) + days=getattr(settings, 'PLANS_DEFAULT_GRACE_PERIOD', 30)) self.activate() # this will call self.save() def extend_account(self, plan, pricing): @@ -416,7 +416,7 @@ def name(self): def is_ready_for_payment(self): return self.status == self.STATUS.NEW and (now() - self.created).days < getattr( - settings, 'ORDER_EXPIRATION', 14) + settings, 'PLANS_ORDER_EXPIRATION', 14) def complete_order(self): if self.completed is None: @@ -497,7 +497,7 @@ class Invoice(models.Model): duplicates = InvoiceDuplicateManager() class NUMBERING: - """Used as a choices for settings.INVOICE_COUNTER_RESET""" + """Used as a choices for settings.PLANS_INVOICE_COUNTER_RESET""" DAILY = 1 MONTHLY = 2 @@ -553,7 +553,7 @@ def get_absolute_url(self): def clean(self): if self.number is None: - invoice_counter_reset = getattr(settings, 'INVOICE_COUNTER_RESET', Invoice.NUMBERING.MONTHLY) + invoice_counter_reset = getattr(settings, 'PLANS_INVOICE_COUNTER_RESET', Invoice.NUMBERING.MONTHLY) if invoice_counter_reset == Invoice.NUMBERING.DAILY: last_number = Invoice.objects.filter(issued=self.issued, type=self.type).aggregate(Max('number'))[ @@ -567,7 +567,7 @@ def clean(self): 'number__max'] or 0 else: raise ImproperlyConfigured( - "INVOICE_COUNTER_RESET can be set only to these values: daily, monthly, yearly.") + "PLANS_INVOICE_COUNTER_RESET can be set only to these values: daily, monthly, yearly.") self.number = last_number + 1 if self.full_number == "": @@ -585,7 +585,7 @@ def clean(self): def get_full_number(self): """ - Generates on the fly invoice full number from template provided by ``settings.INVOICE_NUMBER_FORMAT``. + Generates on the fly invoice full number from template provided by ``settings.PLANS_INVOICE_NUMBER_FORMAT``. ``Invoice`` object is provided as ``invoice`` variable to the template, therefore all object fields can be used to generate full number format. @@ -596,21 +596,21 @@ def get_full_number(self): :return: string (generated full number) """ - format = getattr(settings, "INVOICE_NUMBER_FORMAT", + format = getattr(settings, "PLANS_INVOICE_NUMBER_FORMAT", "{{ invoice.number }}/{% ifequal invoice.type invoice.INVOICE_TYPES.PROFORMA %}PF{% else %}FV{% endifequal %}/{{ invoice.issued|date:'m/Y' }}") return Template(format).render(Context({'invoice': self})) def set_issuer_invoice_data(self): """ - Fills models object with issuer data copied from ``settings.ISSUER_DATA`` + Fills models object with issuer data copied from ``settings.PLANS_INVOICE_ISSUER`` :raise: ImproperlyConfigured """ try: - issuer = getattr(settings, 'ISSUER_DATA') + issuer = getattr(settings, 'PLANS_INVOICE_ISSUER') except: - raise ImproperlyConfigured("Please set ISSUER_DATA in order to make an invoice.") + raise ImproperlyConfigured("Please set PLANS_INVOICE_ISSUER in order to make an invoice.") self.issuer_name = issuer['issuer_name'] self.issuer_street = issuer['issuer_street'] self.issuer_zipcode = issuer['issuer_zipcode'] diff --git a/plans/tasks.py b/plans/tasks.py index c144fa5d..0c88acea 100644 --- a/plans/tasks.py +++ b/plans/tasks.py @@ -15,7 +15,7 @@ def expire_account(): for user in User.objects.select_related('userplan').filter(userplan__active=True, userplan__expire__lt=datetime.date.today()).exclude(userplan__expire=None): user.userplan.expire_account() - notifications_days_before = getattr(settings, 'PLAN_EXPIRATION_REMIND', []) + notifications_days_before = getattr(settings, 'PLANS_EXPIRATION_REMIND', []) if notifications_days_before: days = map(lambda x: datetime.date.today() + datetime.timedelta(days=x), notifications_days_before) diff --git a/plans/taxation/__init__.py b/plans/taxation/__init__.py index aa397fb9..091034bc 100644 --- a/plans/taxation/__init__.py +++ b/plans/taxation/__init__.py @@ -14,20 +14,20 @@ class TaxationPolicy(object): @classmethod def get_default_tax(cls): """ - Gets default tax rate. Simply returns ``settings.TAX`` + Gets default tax rate. Simply returns ``settings.PLANS_TAX`` :return: Decimal() """ - return getattr(settings, 'TAX', None) + return getattr(settings, 'PLANS_TAX', None) @classmethod def get_issuer_country_code(cls): """ - Gets issuers country. Simply returns ``settings.TAX_COUNTRY`` + Gets issuers country. Simply returns ``settings.PLANS_TAX_COUNTRY`` :return: unicode """ - return getattr(settings, 'TAX_COUNTRY', None) + return getattr(settings, 'PLANS_TAX_COUNTRY', None) @classmethod def get_tax_rate(cls, tax_id, country_code): diff --git a/plans/taxation/ru.py b/plans/taxation/ru.py index 7c6e6f2f..d8ea59fb 100644 --- a/plans/taxation/ru.py +++ b/plans/taxation/ru.py @@ -10,10 +10,10 @@ class RussianTaxationPolicy(TaxationPolicy): # This could be inherited unless there is a reason to be custom # def get_default_tax(self): -# return getattr(settings, 'TAX', None) +# return getattr(settings, 'PLANS_TAX', None) # # def get_issuer_country_code(self): -# return getattr(settings, 'TAX_COUNTRY', None) +# return getattr(settings, 'PLANS_TAX_COUNTRY', None) def get_tax_rate(self, tax_id, country_code): # TODO diff --git a/plans/tests/tests.py b/plans/tests/tests.py index ca9850bf..05d750f3 100644 --- a/plans/tests/tests.py +++ b/plans/tests/tests.py @@ -145,7 +145,7 @@ def test_get_full_number_type3(self): self.assertEqual(i.get_full_number(), "123/PF/05/2010") def test_get_full_number_with_settings(self): - settings.INVOICE_NUMBER_FORMAT = "{{ invoice.issued|date:'Y' }}." \ + settings.PLANS_INVOICE_NUMBER_FORMAT = "{{ invoice.issued|date:'Y' }}." \ "{{ invoice.number }}.{{ invoice.issued|date:'m' }}" i = Invoice() i.number = 123 @@ -153,21 +153,21 @@ def test_get_full_number_with_settings(self): self.assertEqual(i.get_full_number(), "2010.123.05") def test_set_issuer_invoice_data_raise(self): - issdata = settings.ISSUER_DATA - del settings.ISSUER_DATA + issdata = settings.PLANS_INVOICE_ISSUER + del settings.PLANS_INVOICE_ISSUER i = Invoice() self.assertRaises(ImproperlyConfigured, i.set_issuer_invoice_data) - settings.ISSUER_DATA = issdata + settings.PLANS_INVOICE_ISSUER = issdata def test_set_issuer_invoice_data(self): i = Invoice() i.set_issuer_invoice_data() - self.assertEqual(i.issuer_name, settings.ISSUER_DATA['issuer_name']) - self.assertEqual(i.issuer_street, settings.ISSUER_DATA['issuer_street']) - self.assertEqual(i.issuer_zipcode, settings.ISSUER_DATA['issuer_zipcode']) - self.assertEqual(i.issuer_city, settings.ISSUER_DATA['issuer_city']) - self.assertEqual(i.issuer_country, settings.ISSUER_DATA['issuer_country']) - self.assertEqual(i.issuer_tax_number, settings.ISSUER_DATA['issuer_tax_number']) + self.assertEqual(i.issuer_name, settings.PLANS_INVOICE_ISSUER['issuer_name']) + self.assertEqual(i.issuer_street, settings.PLANS_INVOICE_ISSUER['issuer_street']) + self.assertEqual(i.issuer_zipcode, settings.PLANS_INVOICE_ISSUER['issuer_zipcode']) + self.assertEqual(i.issuer_city, settings.PLANS_INVOICE_ISSUER['issuer_city']) + self.assertEqual(i.issuer_country, settings.PLANS_INVOICE_ISSUER['issuer_country']) + self.assertEqual(i.issuer_tax_number, settings.PLANS_INVOICE_ISSUER['issuer_tax_number']) def set_buyer_invoice_data(self): i = Invoice() @@ -186,7 +186,7 @@ def set_buyer_invoice_data(self): self.assertEqual(i.buyer_country, u.billinginfo.shipping_country) def test_invoice_number(self): - settings.INVOICE_NUMBER_FORMAT = "{{ invoice.number }}/{% ifequal " \ + settings.PLANS_INVOICE_NUMBER_FORMAT = "{{ invoice.number }}/{% ifequal " \ "invoice.type invoice.INVOICE_TYPES.PROFORMA %}PF{% else %}FV" \ "{% endifequal %}/{{ invoice.issued|date:'m/Y' }}" o = Order.objects.all()[0] @@ -202,15 +202,15 @@ def test_invoice_number(self): self.assertEqual(i.full_number, '1/FV/05/2010') def test_invoice_number_daily(self): - settings.INVOICE_NUMBER_FORMAT = "{{ invoice.number }}/{% ifequal " \ + settings.PLANS_INVOICE_NUMBER_FORMAT = "{{ invoice.number }}/{% ifequal " \ "invoice.type invoice.INVOICE_TYPES.PROFORMA %}PF{% else %}FV" \ "{% endifequal %}/{{ invoice.issued|date:'d/m/Y' }}" - settings.INVOICE_COUNTER_RESET = Invoice.NUMBERING.DAILY + settings.PLANS_INVOICE_COUNTER_RESET = Invoice.NUMBERING.DAILY user = User.objects.get(username='test1') plan_pricing = PlanPricing.objects.all()[0] - tax = getattr(settings, "TAX") - currency = getattr(settings, "CURRENCY") + tax = getattr(settings, "PLANS_TAX") + currency = getattr(settings, "PLANS_CURRENCY") o1 = Order(user=user, plan=plan_pricing.plan, pricing=plan_pricing.pricing, amount=plan_pricing.price, tax=tax, currency=currency) @@ -254,15 +254,15 @@ def test_invoice_number_daily(self): self.assertEqual(i3.full_number, "1/FV/04/05/2001") def test_invoice_number_monthly(self): - settings.INVOICE_NUMBER_FORMAT = "{{ invoice.number }}/{% ifequal " \ + settings.PLANS_INVOICE_NUMBER_FORMAT = "{{ invoice.number }}/{% ifequal " \ "invoice.type invoice.INVOICE_TYPES.PROFORMA %}PF{% else %}FV" \ "{% endifequal %}/{{ invoice.issued|date:'m/Y' }}" - settings.INVOICE_COUNTER_RESET = Invoice.NUMBERING.MONTHLY + settings.PLANS_INVOICE_COUNTER_RESET = Invoice.NUMBERING.MONTHLY user = User.objects.get(username='test1') plan_pricing = PlanPricing.objects.all()[0] - tax = getattr(settings, "TAX") - currency = getattr(settings, "CURRENCY") + tax = getattr(settings, "PLANS_TAX") + currency = getattr(settings, "PLANS_CURRENCY") o1 = Order(user=user, plan=plan_pricing.plan, pricing=plan_pricing.pricing, amount=plan_pricing.price, tax=tax, currency=currency) @@ -307,15 +307,15 @@ def test_invoice_number_monthly(self): self.assertEqual(i3.full_number, "1/FV/06/2002") def test_invoice_number_annually(self): - settings.INVOICE_NUMBER_FORMAT = "{{ invoice.number }}/{% ifequal " \ + settings.PLANS_INVOICE_NUMBER_FORMAT = "{{ invoice.number }}/{% ifequal " \ "invoice.type invoice.INVOICE_TYPES.PROFORMA %}PF{% else %}FV" \ "{% endifequal %}/{{ invoice.issued|date:'Y' }}" - settings.INVOICE_COUNTER_RESET = Invoice.NUMBERING.ANNUALLY + settings.PLANS_INVOICE_COUNTER_RESET = Invoice.NUMBERING.ANNUALLY user = User.objects.get(username='test1') plan_pricing = PlanPricing.objects.all()[0] - tax = getattr(settings, "TAX") - currency = getattr(settings, "CURRENCY") + tax = getattr(settings, "PLANS_TAX") + currency = getattr(settings, "PLANS_CURRENCY") o1 = Order(user=user, plan=plan_pricing.plan, pricing=plan_pricing.pricing, amount=plan_pricing.price, tax=tax, currency=currency) @@ -442,37 +442,37 @@ def setUp(self): self.policy = EUTaxationPolicy() def test_none(self): - with self.settings(TAX=Decimal('23.0'), TAX_COUNTRY='PL'): + with self.settings(PLANS_TAX=Decimal('23.0'), PLANS_TAX_COUNTRY='PL'): self.assertEqual(self.policy.get_tax_rate(None, None), Decimal('23.0')) def test_private_nonEU(self): - with self.settings(TAX=Decimal('23.0'), TAX_COUNTRY='PL'): + with self.settings(PLANS_TAX=Decimal('23.0'), PLANS_TAX_COUNTRY='PL'): self.assertEqual(self.policy.get_tax_rate(None, 'RU'), None) def test_private_EU_same(self): - with self.settings(TAX=Decimal('23.0'), TAX_COUNTRY='PL'): + with self.settings(PLANS_TAX=Decimal('23.0'), PLANS_TAX_COUNTRY='PL'): self.assertEqual(self.policy.get_tax_rate(None, 'PL'), Decimal('23.0')) def test_private_EU_notsame(self): - with self.settings(TAX=Decimal('23.0'), TAX_COUNTRY='PL'): + with self.settings(PLANS_TAX=Decimal('23.0'), PLANS_TAX_COUNTRY='PL'): self.assertEqual(self.policy.get_tax_rate(None, 'AT'), Decimal('20.0')) def test_company_nonEU(self): - with self.settings(TAX=Decimal('23.0'), TAX_COUNTRY='PL'): + with self.settings(PLANS_TAX=Decimal('23.0'), PLANS_TAX_COUNTRY='PL'): self.assertEqual(self.policy.get_tax_rate('123456', 'RU'), None) def test_company_EU_same(self): - with self.settings(TAX=Decimal('23.0'), TAX_COUNTRY='PL'): + with self.settings(PLANS_TAX=Decimal('23.0'), PLANS_TAX_COUNTRY='PL'): self.assertEqual(self.policy.get_tax_rate('123456', 'PL'), Decimal('23.0')) @mock.patch("vatnumber.check_vies", lambda x: True) def test_company_EU_notsame_vies_ok(self): - with self.settings(TAX=Decimal('23.0'), TAX_COUNTRY='PL'): + with self.settings(PLANS_TAX=Decimal('23.0'), PLANS_TAX_COUNTRY='PL'): self.assertEqual(self.policy.get_tax_rate('123456', 'AT'), None) @mock.patch("vatnumber.check_vies", lambda x: False) def test_company_EU_notsame_vies_not_ok(self): - with self.settings(TAX=Decimal('23.0'), TAX_COUNTRY='PL'): + with self.settings(PLANS_TAX=Decimal('23.0'), PLANS_TAX_COUNTRY='PL'): self.assertEqual(self.policy.get_tax_rate('123456', 'AT'), Decimal('20.0')) diff --git a/plans/validators.py b/plans/validators.py index 964a4984..622369fe 100644 --- a/plans/validators.py +++ b/plans/validators.py @@ -119,7 +119,7 @@ def plan_validation(user, plan=None, on_activation=False): # if plan is not given, the default is to use current plan of the user plan = user.userplan.plan quota_dict = plan.get_quota_dict() - validators = getattr(settings, 'PLAN_VALIDATORS', {}) + validators = getattr(settings, 'PLANS_VALIDATORS', {}) errors = { 'required_to_activate': [], 'other': [], diff --git a/plans/views.py b/plans/views.py index 1269e60b..ff448f5f 100644 --- a/plans/views.py +++ b/plans/views.py @@ -118,7 +118,7 @@ def get_context_data(self, **kwargs): pass context['plan_table'] = self.get_plan_table(self.object_list) - context['CURRENCY'] = settings.CURRENCY + context['CURRENCY'] = settings.PLANS_CURRENCY return context @@ -159,7 +159,7 @@ def post(self, request, *args, **kwargs): Q(customized=request.user) | Q(customized__isnull=True))) if request.user.userplan.plan != plan: policy = import_name( - getattr(settings, 'PLAN_CHANGE_POLICY', 'plans.plan_change.StandardPlanChangePolicy'))() + getattr(settings, 'PLANS_CHANGE_POLICY', 'plans.plan_change.StandardPlanChangePolicy'))() period = request.user.userplan.days_left() price = policy.get_change_price(request.user.userplan.plan, plan, period) @@ -194,11 +194,10 @@ def recalculate(self, amount, billing_info): tax_session_key = "tax_%s_%s" % (tax_number, country) tax = self.request.session.get(tax_session_key) - if tax is None: - taxation_policy = getattr(settings, 'TAXATION_POLICY', None) + taxation_policy = getattr(settings, 'PLANS_TAXATION_POLICY', None) if not taxation_policy: - raise ImproperlyConfigured('TAXATION_POLICY is not set') + raise ImproperlyConfigured('PLANS_TAXATION_POLICY is not set') taxation_policy = import_name(taxation_policy) tax = str(taxation_policy.get_tax_rate(tax_number, country)) # Because taxation policy could return None which clutters with saving this value @@ -247,9 +246,9 @@ def get_billing_info(self): return None def get_currency(self): - CURRENCY = getattr(settings, 'CURRENCY', '') + CURRENCY = getattr(settings, 'PLANS_CURRENCY', '') if len(CURRENCY) != 3: - raise ImproperlyConfigured('CURRENCY should be configured as 3-letter currency code.') + raise ImproperlyConfigured('PLANS_CURRENCY should be configured as 3-letter currency code.') return CURRENCY def get_price(self): @@ -295,7 +294,7 @@ def get_all_context(self): self.pricing = None def get_policy(self): - policy_class = getattr(settings, 'PLAN_CHANGE_POLICY', 'plans.plan_change.StandardPlanChangePolicy') + policy_class = getattr(settings, 'PLANS_CHANGE_POLICY', 'plans.plan_change.StandardPlanChangePolicy') return import_name(policy_class)() def get_price(self): @@ -336,9 +335,9 @@ class OrderListView(LoginRequired, ListView): def get_context_data(self, **kwargs): context = super(OrderListView, self).get_context_data(**kwargs) - self.CURRENCY = getattr(settings, 'CURRENCY', None) + self.CURRENCY = getattr(settings, 'PLANS_CURRENCY', None) if len(self.CURRENCY) != 3: - raise ImproperlyConfigured('CURRENCY should be configured as 3-letter currency code.') + raise ImproperlyConfigured('PLANS_CURRENCY should be configured as 3-letter currency code.') context['CURRENCY'] = self.CURRENCY return context @@ -442,20 +441,20 @@ class InvoiceDetailView(LoginRequired, DetailView): model = Invoice def get_template_names(self): - return getattr(settings, 'INVOICE_TEMPLATE', 'plans/invoices/PL_EN.html') + return getattr(settings, 'PLANS_INVOICE_TEMPLATE', 'plans/invoices/PL_EN.html') def get_context_data(self, **kwargs): context = super(InvoiceDetailView, self).get_context_data(**kwargs) - context['logo_url'] = getattr(settings, 'INVOICE_LOGO_URL', None) + context['logo_url'] = getattr(settings, 'PLANS_INVOICE_LOGO_URL', None) context['auto_print'] = True return context def get_queryset(self): if self.request.user.is_superuser: - return super(InvoiceDetailView, self).get_queryset() + return super(InvoiceDetailView, self).get_queryset().select_related('order') else: - return super(InvoiceDetailView, self).get_queryset().filter(user=self.request.user) + return super(InvoiceDetailView, self).get_queryset().filter(user=self.request.user).select_related('order') class FakePaymentsView(LoginRequired, SingleObjectMixin, FormView):