def stock_tally(fl, company, user): from apps.haul.views import xls_stock_tally if fl.name.endswith('.xls'): wb = xls_to_xlsx(fl) else: wb = load_workbook(fl) sheets = wb.worksheets inventory_account_no = InventoryAccount.get_next_account_no(company=company) cnt = 0 if company.can_manage_locations(): default_location, created = Location.objects.get_or_create(company=company, name='Default Location') for sheet in sheets: category, category_created = ItemCategory.objects.get_or_create(name=sheet.title, company=company) rows = tuple(sheet.iter_rows()) with transaction.atomic(): unit, created = Unit.objects.get_or_create(name="Pieces", company=company) for row in rows[5:]: params = xls_stock_tally(row) if params.get('particulars') not in ['Grand Total', 'Total', 'total']: rate = empty_to_zero(params.get('rate')) quantity = empty_to_zero(params.get('quantity')) item = Item(name=params.get('particulars'), cost_price=rate, category=category, unit=unit, company=company, oem_no=empty_to_zero(params.get('oem_number'))) cnt += 1 item.save(account_no=inventory_account_no) inventory_account_no += 1 if quantity != 0: if company.can_manage_locations(): default_location.add_items(item, quantity) set_transactions(item.account, datetime.date.today(), ['dr', item.account, quantity]) send_mail('Inventory Stock Import complete', str(cnt) + ' inventory records imported.', settings.DEFAULT_FROM_EMAIL, [user.email], fail_silently=False)
def get_context_data(self, *args, **kwargs): context = super(ViewPartyAccount, self).get_context_data(**kwargs) base_template = 'dashboard.html' pk = int(self.kwargs.get('pk')) obj = get_object_or_404(self.model, pk=pk, company__in=self.request.company.get_all()) journal_entries = JournalEntry.objects.filter(transactions__account_id__in=[obj.customer_account.pk, obj.supplier_account.pk]).order_by('pk', 'date') \ .prefetch_related('transactions', 'content_type', 'transactions__account').select_related() context['party'] = obj context['dr_amount'] = empty_to_zero(obj.customer_account.current_dr) + empty_to_zero(obj.supplier_account.current_dr) context['cr_amount'] = empty_to_zero(obj.customer_account.current_cr) + empty_to_zero(obj.supplier_account.current_cr) context['closing_balance'] = context['dr_amount'] - context['cr_amount'] context['journal_entries'] = journal_entries context['base_template'] = base_template return context
def stock_tally(fl, company, user): from apps.haul.views import xls_stock_tally if fl.name.endswith('.xls'): wb = xls_to_xlsx(fl) else: wb = load_workbook(fl) sheets = wb.worksheets inventory_account_no = InventoryAccount.get_next_account_no( company=company) cnt = 0 if company.can_manage_locations(): default_location, created = Location.objects.get_or_create( company=company, name='Default Location') for sheet in sheets: category, category_created = ItemCategory.objects.get_or_create( name=sheet.title, company=company) rows = tuple(sheet.iter_rows()) with transaction.atomic(): unit, created = Unit.objects.get_or_create(name="Pieces", company=company) for row in rows[5:]: params = xls_stock_tally(row) if params.get('particulars') not in [ 'Grand Total', 'Total', 'total' ]: rate = empty_to_zero(params.get('rate')) quantity = empty_to_zero(params.get('quantity')) item = Item(name=params.get('particulars'), cost_price=rate, category=category, unit=unit, company=company, oem_no=empty_to_zero(params.get('oem_number'))) cnt += 1 item.save(account_no=inventory_account_no) inventory_account_no += 1 if quantity != 0: if company.can_manage_locations(): default_location.add_items(item, quantity) set_transactions(item.account, datetime.date.today(), ['dr', item.account, quantity]) send_mail('Inventory Stock Import complete', str(cnt) + ' inventory records imported.', settings.DEFAULT_FROM_EMAIL, [user.email], fail_silently=False)