# django imports
from django.utils.translation import ugettext_lazy as _
from django.db import models

# lfs imports
from lfs.plugins import OrderNumberGenerator as Base


class OrderNumberGenerator(Base):
    """Generates order numbers and saves the last one.

    **Attributes:**

    id
        The primary key of the order number.

    last
        The last stored/returned order number.

    format
        The format of the integer part of the order number.
    """
    id = models.CharField(primary_key=True, max_length=20)
    last = models.IntegerField(_(u"Last order number"), default=0)
    format = models.CharField(blank=True, max_length=20)

    def get_next(self, formatted=True):
        """Returns the next order number.

        **Parameters:**

        formatted
            If True the number will be returned within the stored format.
        """
        self.last += 1
        self.save()
        if formatted:
            return self.format % self.last
        else:
            return self.last

# django imports
from django.utils.translation import ugettext_lazy as _
from django.db import models

# lfs imports
from lfs.plugins import OrderNumberGenerator as Base


class OrderNumberGenerator(Base):
    """Generates order numbers and saves the last one.

    **Attributes:**

    id
        The primary key of the order number.

    last
        The last stored/returned order number.

    format
        The format of the integer part of the order number.
    """
    id = models.CharField(primary_key=True, max_length=20)
    last = models.IntegerField(_(u"Last order number"), default=0)
    format = models.CharField(blank=True, max_length=20)

    def get_next(self, formatted=True):
        """Returns the next order number.

        **Parameters:**

        formatted
            If True the number will be returned within the stored format.
        """
        self.last += 1
        self.save()
        if formatted and self.format:
            return self.format % self.last
        else:
            return self.last

Check whether there is a format given (this must be checked for validity though).
Check whether there is a format given (this must be checked for validity though).
