コード例 #1
0
ファイル: test_purchase.py プロジェクト: lulzzz/stoq
    def test_constructor_cost(self):
        order = self.create_purchase_order()
        sellable = self.create_sellable()
        sellable.cost = 97

        # If we dont pass a cost, the constructor should get from the sellable
        item = PurchaseItem(store=self.store, sellable=sellable, order=order)
        self.assertEqual(item.cost, 97)

        # Now the cost of the sellable should be ignored.
        item = PurchaseItem(store=self.store, sellable=sellable, order=order,
                            cost=58)
        self.assertEqual(item.cost, 58)
コード例 #2
0
ファイル: test_purchase.py プロジェクト: sarkis89/stoq
    def test_constructor_without_order(self):
        sellable = self.create_sellable()

        # If we dont pass a Order, the constructor should raise an TypeError:
        # 'You must provide a order argument'
        with self.assertRaises(TypeError):
            PurchaseItem(store=self.store, sellable=sellable)
コード例 #3
0
ファイル: test_purchase.py プロジェクト: sarkis89/stoq
    def test_constructor_without_sellable(self):
        order = self.create_purchase_order()

        # If we dont pass a Sellable, the constructor should raise an TypeError:
        # 'You must provide a sellable argument'
        with self.assertRaises(TypeError):
            PurchaseItem(store=self.store, order=order)
コード例 #4
0
ファイル: test_sellable.py プロジェクト: rosalin/stoq
    def test_can_remove(self):
        branch = get_current_branch(self.store)
        sellable = self.create_sellable()
        storable = Storable(product=sellable.product, store=self.store)
        self.failUnless(sellable.can_remove())

        storable.increase_stock(1, branch, 0, None)
        sale = self.create_sale()
        sale.status = Sale.STATUS_QUOTE
        sale.branch = branch
        sale.add_sellable(sellable)
        self.failIf(sellable.can_remove())

        # Can't remove the sellable if it's in a purchase.
        from stoqlib.domain.purchase import PurchaseItem
        sellable = self.create_sellable()
        Storable(product=sellable.product, store=self.store)
        self.assertTrue(sellable.can_remove())
        PurchaseItem(store=self.store,
                     quantity=8, quantity_received=0,
                     cost=125, base_cost=125,
                     sellable=sellable,
                     order=self.create_purchase_order())
        self.assertFalse(sellable.can_remove())

        # The delivery service cannot be removed.
        sellable = sysparam(self.store).DELIVERY_SERVICE.sellable
        self.failIf(sellable.can_remove())
コード例 #5
0
    def test_can_remove(self):
        sellable = Sellable(store=self.store)
        self.assertTrue(sellable.can_remove())

        sellable = self.create_sellable()
        storable = Storable(product=sellable.product, store=self.store)
        self.assertTrue(sellable.can_remove())

        storable.increase_stock(1, self.current_branch,
                                StockTransactionHistory.TYPE_INITIAL, None,
                                self.current_user)
        sale = self.create_sale()
        sale.status = Sale.STATUS_QUOTE
        sale.branch = self.current_branch
        sale.add_sellable(sellable)
        self.assertFalse(sellable.can_remove())

        # Can't remove the sellable if it's in a purchase.
        from stoqlib.domain.purchase import PurchaseItem
        sellable = self.create_sellable()
        Storable(product=sellable.product, store=self.store)
        self.assertTrue(sellable.can_remove())
        PurchaseItem(store=self.store,
                     quantity=8,
                     quantity_received=0,
                     cost=125,
                     base_cost=125,
                     sellable=sellable,
                     order=self.create_purchase_order())
        self.assertFalse(sellable.can_remove())

        # The delivery service cannot be removed.
        sellable = sysparam.get_object(self.store, 'DELIVERY_SERVICE').sellable
        self.assertFalse(sellable.can_remove())
コード例 #6
0
    def create_purchase_order_item(self, order=None):
        if not order:
            order = self.create_purchase_order()

        from stoqlib.domain.purchase import PurchaseItem
        return PurchaseItem(store=self.store,
                            quantity=8, quantity_received=0,
                            cost=125, base_cost=125,
                            sellable=self.create_sellable(),
                            order=order)
コード例 #7
0
ファイル: purchasequotewizard.py プロジェクト: pkaislan/stoq
    def _setup_widgets(self):
        self.quoted_items.connect(
            'selection-changed', self._on_quoted_items__selection_changed)
        self.quoted_items.set_columns(self._get_columns())
        # populate the list
        for quote in self._group.get_items():
            for purchase_item in quote.purchase.get_items():
                if not self._can_purchase(purchase_item):
                    continue

                sellable = purchase_item.sellable
                ordered_qty = \
                    PurchaseItem.get_ordered_quantity(self.store, sellable)

                self.quoted_items.append(Settable(
                    selected=True, order=quote.purchase, item=purchase_item,
                    description=sellable.get_description(),
                    supplier=quote.purchase.supplier_name,
                    quantity=purchase_item.quantity,
                    ordered_quantity=ordered_qty,
                    cost=purchase_item.cost))
コード例 #8
0
ファイル: purchasequotewizard.py プロジェクト: 5l1v3r1/stoq-1
    def _setup_widgets(self):
        self.quoted_items.connect(
            'selection-changed', self._on_quoted_items__selection_changed)
        self.quoted_items.set_columns(self._get_columns())
        # populate the list
        for quote in self._group.get_items():
            for purchase_item in quote.purchase.get_items():
                if not self._can_purchase(purchase_item):
                    continue

                sellable = purchase_item.sellable
                ordered_qty = \
                    PurchaseItem.get_ordered_quantity(self.store, sellable)

                self.quoted_items.append(Settable(
                    selected=True, order=quote.purchase, item=purchase_item,
                    description=sellable.get_description(),
                    supplier=quote.purchase.supplier_name,
                    quantity=purchase_item.quantity,
                    ordered_quantity=ordered_qty,
                    cost=purchase_item.cost))
コード例 #9
0
    def process_one(self, data, fields, store):
        person = store.find(Person, name=data.supplier_name).one()
        if person is None or person.supplier is None:
            raise ValueError(u"%s is not a valid supplier" %
                             (data.supplier_name, ))
        supplier = person.supplier

        person = store.find(Person, name=data.transporter_name).one()
        if person is None or person.transporter is None:
            raise ValueError(u"%s is not a valid transporter" %
                             (data.transporter_name, ))
        transporter = person.transporter

        person = store.find(Person, name=data.branch_name).one()
        if person is None or person.branch is None:
            raise ValueError(u"%s is not a valid branch" %
                             (data.branch_name, ))
        branch = person.branch

        login_user = store.find(LoginUser, username=u'admin').one()
        group = PaymentGroup(store=store)
        purchase = PurchaseOrder(store=store,
                                 status=PurchaseOrder.ORDER_PENDING,
                                 open_date=self.parse_date(data.due_date),
                                 supplier=supplier,
                                 transporter=transporter,
                                 group=group,
                                 responsible=get_current_user(store),
                                 branch=branch)

        for sellable in self.parse_multi(Sellable, data.sellable_list, store):
            if not sellable.product:
                continue
            PurchaseItem(store=store,
                         quantity=int(data.quantity),
                         base_cost=sellable.cost,
                         sellable=sellable,
                         order=purchase)

        method = PaymentMethod.get_by_name(store, data.payment_method)
        method.create_payment(Payment.TYPE_OUT, purchase.group, branch,
                              purchase.purchase_total,
                              self.parse_date(data.due_date))
        purchase.confirm()
        for payment in purchase.payments:
            payment.open_date = purchase.open_date

        receiving_order = ReceivingOrder(responsible=login_user,
                                         supplier=supplier,
                                         invoice_number=int(data.invoice),
                                         transporter=transporter,
                                         branch=branch,
                                         store=store)
        receiving_order.add_purchase(purchase)

        for purchase_item in purchase.get_items():
            ReceivingOrderItem(store=store,
                               cost=purchase_item.sellable.cost,
                               sellable=purchase_item.sellable,
                               quantity=int(data.quantity),
                               purchase_item=purchase_item,
                               receiving_order=receiving_order)
        receiving_order.confirm()