Esempio n. 1
0
 def validate(self, data):
     try:
         input_invoice_start_seq = data['invoice_start_sequence']
     except KeyError:
         input_invoice_start_seq = None
     try:
         input_invoice_prefix_seq = data['invoice_prefix_sequence']
     except KeyError:
         input_invoice_prefix_seq = None
     if input_invoice_start_seq is None or len(
             input_invoice_start_seq) <= 0:
         last_invoice_number = Invoice.objects.filter(
             officesettings_id=self.instance.id).aggregate(
                 Max('number'))['number__max']
         if last_invoice_number is not None:
             data['invoice_start_sequence'] = _unicode(last_invoice_number)
         else:
             data['invoice_start_sequence'] = _unicode(10000)
     if input_invoice_prefix_seq is not None:
         if len(input_invoice_prefix_seq) > 3:
             raise serializers.ValidationError(
                 _('Prefix for invoicing sequence should have 3 char length maximum'
                   ))
         if not re.match('^[A-Za-z]{1,3}$', input_invoice_prefix_seq):
             raise serializers.ValidationError(
                 _('Prefix could only contains alpha characters'))
     return data
Esempio n. 2
0
 def get_invoice_number(self):
     if self.office_settings.invoice_start_sequence is not None and len(self.office_settings.invoice_start_sequence) > 0:
         invoice_number = _unicode(convert_to_long(self.office_settings.invoice_start_sequence))
         self.office_settings.invoice_start_sequence = _unicode(convert_to_long(invoice_number) + 1)
     else :
         invoice_number = _unicode(10000)
         self.office_settings.invoice_start_sequence = _unicode(convert_to_long(invoice_number) + 1)
     return invoice_number
Esempio n. 3
0
 def replace(match):
     val = match.groups()[0]
     if val is not None:
         todisplay = getattr(obj, val)
         if type(todisplay) is float:
             locale_desc = to_locale(get_language())
             return _unicode(locale.str(todisplay))
         else:
             return _unicode(getattr(obj, val))
     return val
Esempio n. 4
0
 def validate(self, data):
     try:
         input_invoice_start_seq = data['invoice_start_sequence']
     except KeyError:
         input_invoice_start_seq = None
     if input_invoice_start_seq is None or len(
             input_invoice_start_seq) <= 0:
         last_invoice_number = Invoice.objects.aggregate(
             Max('number'))['number__max']
         if last_invoice_number is not None:
             data['invoice_start_sequence'] = _unicode(last_invoice_number)
         else:
             data['invoice_start_sequence'] = _unicode(10000)
     return data
Esempio n. 5
0
def settings_event_tracer(officesettings, user, new_value):
    if officesettings.invoice_start_sequence is not None and len(officesettings.invoice_start_sequence) != 0 \
            and officesettings.invoice_start_sequence != new_value :
        event = OfficeEvent()
        event.clazz = OfficeSettings.__name__
        event.type = OfficeSettings.UPDATE_INVOICE_SEQUENCE
        event.comment = _(
            'Invoice sequence updated from %(previous)s to %(actual)s') % {
                'previous': _unicode(officesettings.invoice_start_sequence),
                'actual': _unicode(new_value)
            }
        event.reference = officesettings.id
        event.user = user
        event.clean()
        event.save()