Exemplo n.º 1
0
    def pre_save(self, model_instance, add):
        if self.auto_now or (self.auto_now_add and add):
            if sim.get_simulation() is not None:
                value = sim.get_simulation().today
            else:
                value = datetime.date.today()
            setattr(model_instance, self.attname, value)
            return value
        else:
            return super().pre_save(model_instance, add)


# class CompanyConsts(models.Model):
#     name = models.CharField(max_length=60)
#     value = models.CharField(max_length=60) # CompanyConsts.value = str(value) - >  value = ast.literal_eval(CompanyConsts.value) # or float or integer or str can be
Exemplo n.º 2
0
def populate_whproducts(prod_num, markup_rate, cost_price, self_rate, whp_quantity, day_quantity_range, threshold_days):
    sim = get_simulation()
    whs = populate_wh()
    ps = popualte_products(prod_num, markup_rate, cost_price)
    for wh in whs:
        for product in ps:
            WHProduct.objects.create(self_rate=random.choice(np.arange(self_rate[0], self_rate[1], 0.1)), warehouse=wh, product=product, quantity=random.choice(range(whp_quantity[0], whp_quantity[1], 1)), threshold=sum((get_binominal(day_quantity_range, sim.d_q_r_max_prob) * (random.choice(np.arange(self_rate[0], self_rate[1], 0.1)))) for i in range(threshold_days)), threshold_days=threshold_days)
Exemplo n.º 3
0
def pre_save_Worker(sender, instance, *args, **kwargs):
    if instance.prob_of_worker_fired == 0.0 or not instance.prob_of_worker_fired:
        sim = get_simulation()
        if instance.kind == 'HR':
            instance.prob_of_worker_fired = sim.prob_of_worker_fired_hr
            instance.work_on_dpt = True
        elif instance.kind == 'accounting_manager':
            instance.prob_of_worker_fired = sim.prob_of_worker_fired_am
            instance.work_on_dpt = True
        elif instance.kind == 'pharmacist':
            instance.prob_of_worker_fired = sim.prob_of_worker_fired_ph
            instance.work_on_wh = True
        elif instance.kind == 'director':
            instance.prob_of_worker_fired = sim.prob_of_worker_fired_dir
            instance.work_on_dpt = True
        elif instance.kind == 'cleaner':
            instance.prob_of_worker_fired = sim.prob_of_worker_fired_cl
            instance.work_on_wh = True
        elif instance.kind == 'loader':
            instance.prob_of_worker_fired = sim.prob_of_worker_fired_ld
            instance.work_on_vehicle = True
        elif instance.kind == 'driver':
            instance.prob_of_worker_fired = sim.prob_of_worker_fired_dr
            instance.work_on_vehicle = True
        elif instance.kind == 'sys_admin':
            instance.prob_of_worker_fired = sim.prob_of_worker_fired_sa
            instance.work_on_dpt = True
Exemplo n.º 4
0
 def make_assessment(self, assess, worker, pharmacy):
     sim = get_simulation()
     apps.get_model('assessments.Assessment').objects.create(
         assess=assess,
         worker=worker,
         pharmacy=pharmacy,
         client=self,
         created=sim.today)
Exemplo n.º 5
0
    def get_report(self):
        """after call creating report of TrialBalance
        can call only after creating of TrialBalance instance
        """
        if self.passives.all().exists() and self.assets.all().exists(
        ):  #hasattr(self, "passives") and hasattr(self, "assets"):
            # перед подсчетом всех компонентов необходимо создать новый баланс, чтоб туда могли записыватся те активы и пассивы которые создаются пока производятся подсчеты для этого отчета
            TrialBalance.objects.create(
            )  # -> this is the last TB, that isnt reported right now but used for future assets and passives
            # print(f'\n\nTB: {TrialBalance.objects.order_by("id")[1]}\n\n')
            if TrialBalance.objects.all().count(
            ) == 2:  # if it is the first created TB # cause descending order for id  ( cause maximum_id==last_id )
                self.start_saldo_credit = 0
                self.start_saldo_debit = 0
            elif TrialBalance.objects.all().count() == 3:
                saldo_from = TrialBalance.objects.all().first()
                print(f'\n\n{saldo_from.id}\n\n')
                self.start_saldo_credit = saldo_from.end_saldo_credit
                self.start_saldo_debit = saldo_from.end_saldo_debit
            else:
                # that mean that there is more than 1 object in queryset ( we get penultimate )
                # print(f'\n\n{(TrialBalance.objects.all().order_by("-id")[2:3])}')
                self.start_saldo_credit = (TrialBalance.objects.all().order_by(
                    "-id")[2:3])[0].end_saldo_credit
                self.start_saldo_debit = (TrialBalance.objects.all().order_by(
                    "-id")[2:3])[0].end_saldo_debit

            # calc_turnover()
            dicts_of_accs, totals = self.get_used_accs_with_values()
            self.dicts_of_accs = str(dicts_of_accs)
            # dicts_of_accs = ast.literal_eval(self.dicts_of_accs)
            self.end_saldo_credit = self.start_saldo_credit + totals[
                "all_credits_total"]
            self.end_saldo_debit = self.start_saldo_credit + totals[
                "all_debits_total"]
            self.turnover_credit = totals['all_turnover_credit']
            self.turnover_debit = totals['all_turnover_debit']
            # ast.literal_eval(self.dicts_of_accs)
            self.reported = True
            # self.date_report = datetime.datetime.today() # tiemzone.now()
            self.date_report = get_simulation().today
            self.period = int((self.date_report - self.date_created).days)
            # self.refresh_from_db() # or not needed
            self.save()  # super().save() # hz
            return True
        else:
            return False
Exemplo n.º 6
0
 def get_report(self):  #  TODO check working
     if self.passives.all().exists() and self.assets.all().exists():
         # self.assets.objects.filter()
         # Assets.objects.filter(assets__ab_id=self.id)
         self.assets_total = sum([(asset.debit_value - asset.credit_value)
                                  for asset in self.assets.all()
                                  ])  # check without []
         self.passives_total = sum([
             (passive.debit_value - passive.credit_value)
             for passive in self.passives.all()
         ])
         self.reported = True
         self.date_report = get_simulation().today  # tiemzone.now()
         self.period = int((self.date_report - self.date_created).days)
         # self.refresh_from_db() # or not needed
         self.save()  # super().save() # hz
         AccountingBalance.objects.create()  # then ass and pass ad to it
         return True
     else:
         return False
Exemplo n.º 7
0
def popualte_products(prod_num, markup_rate, cost_price):
    sim = get_simulation()
    product_list = []
    for product in range(prod_num):
        product_list.append(Product.objects.create(markup_rate=random.choice(np.arange(markup_rate[0], markup_rate[1], 0.01)), cost_price=get_float_binominal(cost_price, sim.product_cost_price_max_prob), name=f'name_#{product}', dozation=f'dozation_#{product}'))
    return product_list
Exemplo n.º 8
0
def accounting_main_page(request):
    if get_simulation() is not None:
        simulations_exists = True
    context = {"simulations_exists": simulations_exists}
    return render(request, 'accounting_main_page.html', context)