示例#1
0
    def confirm(self, confirm_date=None):
        """Confirms the purchase order

        :param confirm_data: optional, datetime
        """
        if confirm_date is None:
            confirm_date = TransactionTimestamp()

        if self.status not in [PurchaseOrder.ORDER_PENDING,
                               PurchaseOrder.ORDER_CONSIGNED]:
            raise ValueError(
                _(u'Invalid order status, it should be '
                  u'ORDER_PENDING or ORDER_CONSIGNED, got %s') % (
                      self.get_status_str(), ))

        transaction = IPaymentTransaction(self)
        transaction.confirm()

        if self.supplier:
            self.group.recipient = self.supplier.person

        self.responsible = get_current_user(self.store)
        self.status = PurchaseOrder.ORDER_CONFIRMED
        self.confirm_date = confirm_date

        Event.log(self.store, Event.TYPE_ORDER,
                  _(u"Order %s, total value %2.2f, supplier '%s' "
                    u"is now confirmed") % (self.identifier,
                                            self.get_purchase_total(),
                                            self.supplier.person.name))
示例#2
0
文件: payment.py 项目: romaia/stoq
    def pay(self, paid_date=None, paid_value=None, account=None):
        """Pay the current payment set its status as :obj:`.STATUS_PAID`"""
        if self.status != Payment.STATUS_PENDING:
            raise ValueError(_(u"This payment is already paid."))
        self._check_status(self.STATUS_PENDING, u'pay')

        paid_value = paid_value or (self.value - self.discount +
                                    self.interest)
        self.paid_value = paid_value
        self.paid_date = paid_date or TransactionTimestamp()
        self.status = self.STATUS_PAID

        if (self.is_separate_payment() or
            self.method.operation.create_transaction()):
            AccountTransaction.create_from_payment(self, account)

        sale = self.group and self.group.sale
        if sale:
            transaction = IPaymentTransaction(sale)
            transaction.create_commission(self)

        if self.value == self.paid_value:
            msg = _(u"{method} payment with value {value:.2f} was paid").format(
                    method=self.method.method_name,
                    value=self.value)
        else:
            msg = _(u"{method} payment with value original value "
                    u"{original_value:.2f} was paid with value "
                    u"{value:.2f}").format(
                    method=self.method.method_name,
                    original_value=self.value,
                    value=self.paid_value)
        Event.log(Event.TYPE_PAYMENT, msg.capitalize())
示例#3
0
    def confirm(self, confirm_date=None):
        """Confirms the purchase order

        :param confirm_data: optional, datetime
        """
        if confirm_date is None:
            confirm_date = TransactionTimestamp()

        if self.status not in [
                PurchaseOrder.ORDER_PENDING, PurchaseOrder.ORDER_CONSIGNED
        ]:
            fmt = _(u'Invalid order status, it should be '
                    u'ORDER_PENDING or ORDER_CONSIGNED, got %s')
            raise ValueError(fmt % (self.get_status_str(), ))

        transaction = IPaymentTransaction(self)
        transaction.confirm()

        if self.supplier:
            self.group.recipient = self.supplier.person

        self.responsible = get_current_user(self.store)
        self.status = PurchaseOrder.ORDER_CONFIRMED
        self.confirm_date = confirm_date

        Event.log(
            self.store, Event.TYPE_ORDER,
            _(u"Order %s, total value %2.2f, supplier '%s' "
              u"is now confirmed") %
            (self.identifier, self.get_purchase_total(),
             self.supplier.person.name))
示例#4
0
    def cancel(self):
        """Cancels the purchase order
        """
        assert self.can_cancel()

        # we have to cancel the payments too
        transaction = IPaymentTransaction(self)
        transaction.cancel()

        self.status = self.ORDER_CANCELLED
示例#5
0
    def cancel(self):
        """Cancels the purchase order
        """
        assert self.can_cancel()

        # we have to cancel the payments too
        transaction = IPaymentTransaction(self)
        transaction.cancel()

        self.status = self.ORDER_CANCELLED
示例#6
0
    def pay(self, paid_date=None, paid_value=None, account=None):
        """Pay the current payment set its status as :obj:`.STATUS_PAID`

        If this payment belongs to a sale, and all other payments from the sale
        are paid then the sale will be set as paid.
        """
        if self.status != Payment.STATUS_PENDING:
            raise ValueError(_(u"This payment is already paid."))
        self._check_status(self.STATUS_PENDING, u'pay')

        paid_value = paid_value or (self.value - self.discount +
                                    self.interest)
        self.paid_value = paid_value
        self.paid_date = paid_date or TransactionTimestamp()
        self.status = self.STATUS_PAID

        if (self.is_separate_payment() or
            self.method.operation.create_transaction()):
            AccountTransaction.create_from_payment(self, account)

        sale = self.group and self.group.sale
        if sale:
            transaction = IPaymentTransaction(sale)
            transaction.create_commission(self)

            # When paying payments of a sale, check if the other payments are
            # paid. If they are, this means you can change the sale status to
            # paid as well.
            if sale.can_set_paid():
                sale.set_paid()

        if self.value == self.paid_value:
            msg = _(u"{method} payment with value {value:.2f} was paid").format(
                method=self.method.method_name,
                value=self.value)
        else:
            msg = _(u"{method} payment with value original value "
                    u"{original_value:.2f} was paid with value "
                    u"{value:.2f}").format(
                method=self.method.method_name,
                original_value=self.value,
                value=self.paid_value)
        Event.log(self.store, Event.TYPE_PAYMENT, msg.capitalize())
示例#7
0
文件: payment.py 项目: rosalin/stoq
    def pay(self, paid_date=None, paid_value=None, account=None):
        """Pay the current payment set its status as :obj:`.STATUS_PAID`

        If this payment belongs to a sale, and all other payments from the sale
        are paid then the sale will be set as paid.
        """
        if self.status != Payment.STATUS_PENDING:
            raise ValueError(_(u"This payment is already paid."))
        self._check_status(self.STATUS_PENDING, u'pay')

        paid_value = paid_value or (self.value - self.discount +
                                    self.interest)
        self.paid_value = paid_value
        self.paid_date = paid_date or TransactionTimestamp()
        self.status = self.STATUS_PAID

        if (self.is_separate_payment() or
            self.method.operation.create_transaction()):
            AccountTransaction.create_from_payment(self, account)

        sale = self.group and self.group.sale
        if sale:
            transaction = IPaymentTransaction(sale)
            transaction.create_commission(self)

            # When paying payments of a sale, check if the other payments are
            # paid. If they are, this means you can change the sale status to
            # paid as well.
            if sale.can_set_paid():
                sale.set_paid()

        if self.value == self.paid_value:
            msg = _(u"{method} payment with value {value:.2f} was paid").format(
                method=self.method.method_name,
                value=self.value)
        else:
            msg = _(u"{method} payment with value original value "
                    u"{original_value:.2f} was paid with value "
                    u"{value:.2f}").format(
                method=self.method.method_name,
                original_value=self.value,
                value=self.paid_value)
        Event.log(self.store, Event.TYPE_PAYMENT, msg.capitalize())