Ejemplo n.º 1
0
    def discount_changed(self, ar):
        if not self.product:
            return

        tt = self.voucher.get_trade_type()
        catalog_price = tt.get_catalog_price(self.product)

        if catalog_price is None:
            return
        # assert self.vat_class == self.product.vat_class
        rule = self.get_vat_rule()
        if rule is None:
            return
        cat_rule = rt.modules.vat.VatRule.get_vat_rule(
            get_default_vat_regime, self.get_vat_class(tt),
            dd.plugins.countries.get_my_country(),
            dd.today())
        if cat_rule is None:
            return
        if rule.rate != cat_rule.rate:
            catalog_price = remove_vat(catalog_price, cat_rule.rate)
            catalog_price = add_vat(catalog_price, cat_rule.rate)

        if self.discount is None:
            self.unit_price = myround(catalog_price)
        else:
            self.unit_price = myround(
                catalog_price * (HUNDRED - self.discount) / HUNDRED)
        self.unit_price_changed(ar)
Ejemplo n.º 2
0
    def discount_changed(self, ar):
        if not self.product:
            return

        tt = self.voucher.get_trade_type()
        catalog_price = tt.get_catalog_price(self.product)

        if catalog_price is None:
            return
        # assert self.vat_class == self.product.vat_class
        rule = self.get_vat_rule()
        if rule is None:
            return
        cat_rule = rt.modules.vat.VatRule.get_vat_rule(
            get_default_vat_regime, self.get_vat_class(tt),
            dd.plugins.countries.get_my_country(), dd.today())
        if cat_rule is None:
            return
        if rule.rate != cat_rule.rate:
            catalog_price = remove_vat(catalog_price, cat_rule.rate)
            catalog_price = add_vat(catalog_price, cat_rule.rate)

        if self.discount is None:
            self.unit_price = myround(catalog_price)
        else:
            self.unit_price = myround(catalog_price *
                                      (HUNDRED - self.discount) / HUNDRED)
        self.unit_price_changed(ar)
Ejemplo n.º 3
0
 def product_changed(self, ar):
     if self.product:
         self.title = self.product.name
         self.description = self.product.description
         if self.qty is None:
             self.qty = Decimal("1")
         if self.product.price is not None:
             self.unit_price = myround(self.product.price * \
                 (HUNDRED - self.discount) / HUNDRED)
             self.unit_price_changed(ar)
Ejemplo n.º 4
0
 def product_changed(self, ar):
     if self.product:
         self.title = self.product.name
         self.description = self.product.description
         if self.qty is None:
             self.qty = Decimal("1")
         if self.product.price is not None:
             self.unit_price = myround(self.product.price * \
                 (HUNDRED - self.discount) / HUNDRED)
             self.unit_price_changed(ar)
Ejemplo n.º 5
0
def objects():

    Journal = rt.models.ledger.Journal
    Company = rt.models.contacts.Company

    USERS = Cycler(settings.SITE.user_model.objects.all())

    PROVIDERS = Cycler(
        Company.objects.filter(
            sepa_accounts__iban__isnull=False).order_by('id'))

    JOURNAL_P = Journal.objects.get(ref="PRC")
    ACCOUNTS = Cycler(JOURNAL_P.get_allowed_accounts())
    AMOUNTS = Cycler([
        Decimal(x)
        for x in "20 29.90 39.90 99.95 199.95 599.95 1599.99".split()
    ])
    AMOUNT_DELTAS = Cycler(
        [Decimal(x) for x in "0 0.60 1.10 1.30 2.50".split()])
    DATE_DELTAS = Cycler((1, 2, 3, 4, 5, 6, 7))
    INFLATION_RATE = Decimal("0.02")
    """"purchase stories" : each story represents a provider who sends
    monthly invoices.

    """
    PURCHASE_STORIES = []
    for i in range(5):
        # provider, (account,amount)
        story = (PROVIDERS.pop(), [])
        story[1].append((ACCOUNTS.pop(), AMOUNTS.pop()))
        if i % 3:
            story[1].append((ACCOUNTS.pop(), AMOUNTS.pop()))
        PURCHASE_STORIES.append(story)

    START_YEAR = dd.plugins.ledger.start_year
    date = datetime.date(START_YEAR, 1, 1)
    end_date = settings.SITE.demo_date(-10)  # + delta(years=-2)
    # end_date = datetime.date(START_YEAR+1, 5, 1)
    # print(20151216, START_YEAR, settings.SITE.demo_date(), end_date - date)
    while date < end_date:

        for story in PURCHASE_STORIES:
            vd = date + delta(days=DATE_DELTAS.pop())
            invoice = vat.VatAccountInvoice(
                journal=JOURNAL_P,
                partner=story[0],
                user=USERS.pop(),
                voucher_date=vd,
                # payment_term=PAYMENT_TERMS.pop(),
                entry_date=vd + delta(days=1))
            yield invoice
            for account, amount in story[1]:
                amount += amount + \
                    (amount * INFLATION_RATE * (date.year - START_YEAR))
                item = vat.InvoiceItem(voucher=invoice,
                                       account=account,
                                       total_incl=myround(amount) +
                                       AMOUNT_DELTAS.pop())
                item.total_incl_changed(REQUEST)
                item.before_ui_save(REQUEST)
                #~ if item.total_incl:
                #~ print "20121208 ok", item
                #~ else:
                #~ if item.product.price:
                #~ raise Exception("20121208")
                yield item
            invoice.register(REQUEST)
            invoice.save()

        date += delta(months=1)
Ejemplo n.º 6
0
def objects():

    Journal = rt.models.ledger.Journal
    Company = rt.models.contacts.Company

    USERS = Cycler(settings.SITE.user_model.objects.all())

    PROVIDERS = Cycler(Company.objects.filter(sepa_accounts__iban__isnull=False).order_by("id"))

    JOURNAL_P = Journal.objects.get(ref="PRC")
    ACCOUNTS = Cycler(JOURNAL_P.get_allowed_accounts())
    AMOUNTS = Cycler([Decimal(x) for x in "20 29.90 39.90 99.95 199.95 599.95 1599.99".split()])
    AMOUNT_DELTAS = Cycler([Decimal(x) for x in "0 0.60 1.10 1.30 2.50".split()])
    DATE_DELTAS = Cycler((1, 2, 3, 4, 5, 6, 7))
    INFLATION_RATE = Decimal("0.02")

    """"purchase stories" : each story represents a provider who sends
    monthly invoices.

    """
    PURCHASE_STORIES = []
    for i in range(5):
        # provider, (account,amount)
        story = (PROVIDERS.pop(), [])
        story[1].append((ACCOUNTS.pop(), AMOUNTS.pop()))
        if i % 3:
            story[1].append((ACCOUNTS.pop(), AMOUNTS.pop()))
        PURCHASE_STORIES.append(story)

    START_YEAR = dd.plugins.ledger.start_year
    date = datetime.date(START_YEAR, 1, 1)
    end_date = settings.SITE.demo_date(-10)  # + delta(years=-2)
    # end_date = datetime.date(START_YEAR+1, 5, 1)
    # print(20151216, START_YEAR, settings.SITE.demo_date(), end_date - date)
    while date < end_date:

        for story in PURCHASE_STORIES:
            vd = date + delta(days=DATE_DELTAS.pop())
            invoice = vat.VatAccountInvoice(
                journal=JOURNAL_P,
                partner=story[0],
                user=USERS.pop(),
                voucher_date=vd,
                # payment_term=PAYMENT_TERMS.pop(),
                entry_date=vd + delta(days=1),
            )
            yield invoice
            for account, amount in story[1]:
                amount += amount + (amount * INFLATION_RATE * (date.year - START_YEAR))
                item = vat.InvoiceItem(
                    voucher=invoice, account=account, total_incl=myround(amount) + AMOUNT_DELTAS.pop()
                )
                item.total_incl_changed(REQUEST)
                item.before_ui_save(REQUEST)
                # ~ if item.total_incl:
                # ~ print "20121208 ok", item
                # ~ else:
                # ~ if item.product.price:
                # ~ raise Exception("20121208")
                yield item
            invoice.register(REQUEST)
            invoice.save()

        date += delta(months=1)