Пример #1
0
class Product(dd.Model):
    product_name = models.CharField("Product ", max_length=25,null=True , blank=True)
    product_type = models.CharField("Product Type", max_length=25, null=True, blank=True)
    #product_price= models.DecimalField("Price", decimal_places=2, max_digits=10)
    #product_qt=models.IntegerField("Quantity")
    product_qt = dd.QuantityField()#modified with Hand only
    last_qt = dd.QuantityField(default='0')
    rest_qt = dd.QuantityField()
    #new_qt = dd.QuantityField()
    new_qt = models.BooleanField(default=False)
    product_price = dd.PriceField()

    def __str__(self):
        #not work self.product_qt = self.product_qt - Delivery.qty
        return "%s ,%s EUR |*%s EUR*" % (self.product_name, self.product_price, self.product_qt * self.product_price)
Пример #2
0
class QtyVatItemBase(VatItemBase):
    """Model mixin for items of a :class:`VatTotal`, adds `unit_price` and
`qty`.

    Abstract Base class for :class:`lino_cosi.lib.sales.InvoiceItem` and
    :class:`lino_cosi.lib.sales.OrderItem`, i.e. the lines of invoices
    *with* unit prices and quantities.

    """
    class Meta:
        abstract = True

    unit_price = dd.PriceField(_("Unit price"), blank=True, null=True)
    qty = dd.QuantityField(_("Quantity"), blank=True, null=True)

    def unit_price_changed(self, ar):
        self.reset_totals(ar)

    def qty_changed(self, ar):
        self.reset_totals(ar)

    def reset_totals(self, ar):
        super(QtyVatItemBase, self).reset_totals(ar)
        # if not self.voucher.auto_compute_totals:
        #     if self.qty:
        #         if self.voucher.item_vat:
        #             self.unit_price = self.total_incl / self.qty
        #         else:
        #             self.unit_price = self.total_base / self.qty

        if self.unit_price is not None and self.qty is not None:
            self.set_amount(ar, myround(self.unit_price * self.qty))
Пример #3
0
class StartedEnded(Started, Ended):

    class Meta:
        abstract = True

    def save(self, *args, **kw):
        """
        Fills default value end_date
        """
        if self.end_time and not self.end_date:
            self.end_date = self.start_date
        super(Ended, self).save(*args, **kw)

    def get_duration(self):
        st = self.get_datetime('start')
        et = self.get_datetime('end')
        if st is None or et is None:
            return None
        if et < st:
            return None  # negative duration not supported
        return Duration(et - st)

    @dd.virtualfield(dd.QuantityField(_("Duration")))
    def duration(self, ar):
        return self.get_duration()
Пример #4
0
class Item(dd.Model):
    name = models.CharField(max_length=50)
    qty = dd.QuantityField(default='1')
    discount = dd.QuantityField()
    price = dd.PriceField()

    def __unicode__(self):
        if self.discount is None:
            return "%s x %s at %s = %s EUR" % (self.qty, self.name, self.price,
                                               self.total())
        else:
            return "%s x %s at %s (-%s) = %s EUR" % (
                self.qty, self.name, self.price, self.discount, self.total())

    def total(self):
        if self.discount is None:
            return self.qty * self.price
        else:
            return self.qty * (1 - self.discount) * self.price
Пример #5
0
class OrderItem(SequencedVoucherItem):
    class Meta:
        app_label = 'orders'
        abstract = dd.is_abstract_model(__name__, 'OrderItem')
        verbose_name = _("Order item")
        verbose_name_plural = _("Order items")

    allow_cascaded_delete = 'voucher'

    voucher = dd.ForeignKey('orders.Order', related_name='items')
    # title = models.CharField(_("Heading"), max_length=200, blank=True)
    product = dd.ForeignKey('products.Product', blank=True, null=True)
    qty = dd.QuantityField(_("Quantity"), blank=True, null=True)
    # unit_price = dd.PriceField(_("Unit price"), blank=True, null=True)
    remark = models.CharField(_("Remark"), max_length=200, blank=True)
Пример #6
0
class Ended(CombinedDateTime):
    """Mixin for models with two fields :attr:`end_date` and
    :attr:`end_time`
    Models inheriting from this must also inherit from Started.

    .. attribute:: end_date
    .. attribute:: end_time

    """
    class Meta:
        abstract = True

    end_date = models.DateField(blank=True,
                                null=True,
                                verbose_name=_("End Date"))
    end_time = models.TimeField(blank=True,
                                null=True,
                                verbose_name=_("End Time"))

    def get_duration(self):
        """Return the duration in hours."""
        if not self.start_date:
            return None
        if not self.start_time:
            return None
        if not self.end_time:
            return None

        ed = self.end_date or self.start_date

        st = datetime.datetime.combine(self.start_date, self.start_time)
        et = datetime.datetime.combine(ed, self.end_time)

        if et < st:
            return None  # negative duration not supported
        # print 20151127, repr(et), repr(st)
        return Duration(et - st)

    @dd.virtualfield(dd.QuantityField(_("Duration")))
    def duration(self, ar):
        return self.get_duration()
Пример #7
0
class Delivery(dd.Model):

    client1 = dd.ForeignKey(Client1)
    product = dd.ForeignKey(Product)
    designation = models.CharField("Designation",default='give_same_Product_Name', max_length=40, null=True,blank=True)
    #price = models.DecimalField("Price", decimal_places=2, max_digits=10)
    price=dd.PriceField(default=0)
    discount=dd.QuantityField(null=True ,blank=True)
    #date = models.DateField(auto_now=True) for update auto_now_add for create
    date = models.DateField(auto_now_add=True)
    hour = models.TimeField(auto_now_add=True)
    qty=dd.QuantityField(default='1')
    total_d=dd.PriceField(default=0)

    def __str__(self):

        if self.discount is None:
            self.total_d=self.total()
            self.reduce()

            return "%s x %s  = %s EUR" % (self.qty, self.price, self.total_d)
        else:
            self.total_d=self.total()
            self.reduce()


            return "%s x %s  (-%s) = %s EUR" % (self.qty,  self.price, self.discount, self.total_d)


    def total(self):
        if self.discount is None:
            return self.qty * self.price
        else:
            return self.qty * (1 - self.discount) * self.price

    def reduce(self):

        for self.p in Product.objects.all():

             #if self.p.product_name =='apple' :
              #self.p.product_qt = 999
              #self.p.save()

#  collect the product_name
  #       if self.p.product_name == self.product.product_name:
  #          self.designation = self.product.product_name
  #          self.save()

         if self.p.product_price == self.product.product_price:
           self.price = self.product.product_price
           self.save()

         if self.p.product_name == self.designation:
            self.p.last_qt= self.qty
            self.p.save()
            self.p.rest_qt=self.p.product_qt - self.qty
            self.p.save()
            self.p.new_qt=True
            self.p.save()
         if self.p.product_name == self.product.product_name:
               self.designation = self.product.product_name + '+'
               self.save()

         if self.p.product_name == self.product.product_name:
               self.p.product_qt = self.product.rest_qt
               self.p.save()