def _processCompanyInfo(self, telnum, ico, dic, account, user): try: ci = CompanyInfo.objects.get(user=user) except CompanyInfo.DoesNotExist: ci = CompanyInfo(user=user) ci.bankaccount = account ci.inum = ico ci.tinum = dic ci.phone = telnum ci.save()
def handle(self, *args, **options): activate(settings.LANGUAGE_CODE) logging.basicConfig() town = getattr(options, 'town', 'plzen') with open(args[0]) as f: parsed_data = billparser.TMobileCSVBillParser(f).parsed for num, _ in parsed_data.items(): try: cInfo = CompanyInfo.objects.get(phone=num) except CompanyInfo.DoesNotExist: u = User(username=str(num), first_name='new', last_name=str(num)) u.save() cInfo = CompanyInfo(user=u, phone=num, town=town) cInfo.save() try: phoneInfo = PhoneServiceInfo.objects.get(user=cInfo.user) except PhoneServiceInfo.DoesNotExist: phoneInfo = PhoneServiceInfo(user=cInfo.user, bookedcredit=5) phoneInfo.save()
verbose_name = _('credit change record') verbose_name_plural = _('credit change records') ordering = ['-date'] change = models.FloatField(_('change')) increase = models.BooleanField(_('increase')) currency = models.ForeignKey(Thing, verbose_name=_('currency')) company = models.ForeignKey(CompanyInfo, related_name='changeRecords') date = models.DateField(verbose_name=_('date'), editable=False, auto_now_add=True) detail = models.TextField(_('detail'), max_length=512) account_change.connect(on_account_change) CompanyInfo.add_to_class('debtbegin', models.DateField(_('debt begin'), blank=True, null=True, default=None, editable=False, help_text=_('Date of cross zero in any of credits of the user')) ) def getCurrentCredit(self, currency=Thing.objects.get_default()): """ Computes total from all credit changes. """ total = 0 for cr in self.changeRecords.filter(currency=currency): total += cr.change return total CompanyInfo.getCurrentCredit = getCurrentCredit