コード例 #1
0
 def on_confirm(self):
     # We are using this hook as a callback for the finish button
     branch = self.store.fetch(self.model.branch)
     responsible = self.store.fetch(self.model.user)
     query = self._get_sellables_query()
     return Inventory.create_inventory(self.store, branch, api.get_current_station(self.store),
                                       responsible, query)
コード例 #2
0
ファイル: producteditor.py プロジェクト: stoq/stoq
 def _register_inventory(self):
     query = Storable.id == self._product.id
     inventory = Inventory.create_inventory(
         self.store, branch=self._branch, responsible=api.get_current_user(self.store), query=query
     )
     # At this point, the inventory should have only one item.
     item = inventory.get_items().one()
     item.counted_quantity = item.actual_quantity = self.model.quantity
     # item.product_cost = self.model.cost
     item.reason = self.model.reason
     item.adjust(invoice_number=None)
     inventory.close()
コード例 #3
0
ファイル: producteditor.py プロジェクト: n3zsistemas-bkp/stoq
 def _register_inventory(self):
     query = Storable.id == self._product.id
     inventory = Inventory.create_inventory(
         self.store,
         branch=self._branch,
         responsible=api.get_current_user(self.store),
         query=query)
     # At this point, the inventory should have only one item.
     item = inventory.get_items().one()
     item.counted_quantity = item.actual_quantity = self.model.quantity
     # item.product_cost = self.model.cost
     item.reason = self.model.reason
     item.adjust(invoice_number=None)
     inventory.close()
コード例 #4
0
    def test_create_inventory(self):
        branch = self.create_branch()
        # A category so that we can filter the products we want in the
        # inventory
        cat = self.create_sellable_category()

        #  First, lets create some sellables for our test
        # One storable with stock (it should be in the inventory)
        storable1 = self.create_storable(branch=branch, stock=10)
        storable1.product.sellable.category = cat

        # One storable without stock (it should NOT be in the inventory)
        storable2 = self.create_storable()
        storable2.product.sellable.category = cat

        # One storable with one batch, and stock (it should be in the inventory)
        storable3 = self.create_storable()
        storable3.is_batch = True
        storable3.product.sellable.category = cat
        batch1 = self.create_storable_batch(storable3, u'123')
        storable3.increase_stock(3,
                                 branch,
                                 batch=batch1,
                                 type=StockTransactionHistory.TYPE_INITIAL,
                                 object_id=None,
                                 unit_cost=10)

        # One storable with one batch and a stock item (but without stock).
        # it should be on the inventory
        storable4 = self.create_storable()
        storable4.is_batch = True
        storable4.product.sellable.category = cat
        batch2 = self.create_storable_batch(storable4, u'124')
        storable4.increase_stock(1,
                                 branch,
                                 batch=batch2,
                                 type=StockTransactionHistory.TYPE_INITIAL,
                                 object_id=None,
                                 unit_cost=10)
        storable4.decrease_stock(1,
                                 branch,
                                 batch=batch2,
                                 type=StockTransactionHistory.TYPE_INITIAL,
                                 object_id=None)

        # Then, lets open the inventory
        responsible = self.create_user()
        query = Sellable.category == cat
        inventory = Inventory.create_inventory(self.store, branch, responsible,
                                               query)

        self.assertEquals(inventory.branch, branch)
        self.assertEquals(inventory.responsible, responsible)

        # There should be only 3 items in the inventory
        items = inventory.get_items()
        self.assertEqual(items.count(), 3)
        self.assertEqual(
            set(i.product for i in items),
            set([storable1.product, storable3.product, storable4.product]))

        # Use this examples to also test get_inventory_data
        data = list(inventory.get_inventory_data())
        self.assertEquals(len(data), 3)

        # each row should have 5 items
        row = data[0]
        self.assertEquals(len(row), 5)

        self.assertEquals(set(i[0] for i in data), set(items))
        self.assertEquals(set(i[1] for i in data),
                          set([storable1, storable3, storable4]))
        self.assertEquals(set(i[4] for i in data), set([None, batch1, batch2]))
コード例 #5
0
    def post(self, store):
        branch_id = self.get_arg('branch_id')
        count = self.get_arg('count')

        if not branch_id:
            message = 'No branch_id provided'
            log.error(message)
            abort(400, message)
        if not count:
            message = 'No count provided'
            log.error(message)
            abort(400, message)
        if not isinstance(count, dict):
            message = ('count should be a JSON with barcodes or codes as keys '
                       'and counted quantities as values')
            log.error(message)
            abort(400, message)

        branch = store.get(Branch, branch_id)
        if not branch:
            message = 'Branch {} not found'.format(branch_id)
            log.error(message)
            abort(404, message)

        login_user = self.get_current_user(store)
        station = self.get_current_station(store)

        sellable_count, not_found = self._convert_count_keys(store, count)
        query = Sellable in sellable_count.keys()

        inventory = Inventory.create_inventory(store, branch, station,
                                               login_user, query)
        stock_not_managed = self._apply_count_to_inventory(
            store, sellable_count, inventory)

        items_for_adjustment = inventory.get_items_for_adjustment()

        items_for_adjustment_list = []
        for item_for_adjustment in items_for_adjustment:
            items_for_adjustment_list.append({
                'recorded_quantity':
                str(item_for_adjustment.recorded_quantity.normalize()),
                'counted_quantity':
                str(item_for_adjustment.counted_quantity.normalize()),
                'difference':
                str(item_for_adjustment.difference.normalize()),
                'product': {
                    'sellable': {
                        'barcode':
                        item_for_adjustment.product.sellable.barcode,
                        'code': item_for_adjustment.get_code(),
                        'description': item_for_adjustment.get_description()
                    }
                }
            })

        if not items_for_adjustment_list:
            inventory.cancel()

        return make_response(
            jsonify({
                'id': inventory.id,
                'identifier': inventory.identifier,
                'status': inventory.status,
                'not_found': list(not_found),
                'stock_not_managed': stock_not_managed,
                'items': items_for_adjustment_list
            }), 201)
コード例 #6
0
 def on_confirm(self):
     # We are using this hook as a callback for the finish button
     branch = self.store.fetch(self.model.branch)
     responsible = self.store.fetch(self.model.user)
     query = self._get_sellables_query()
     return Inventory.create_inventory(self.store, branch, responsible, query)
コード例 #7
0
ファイル: test_inventory.py プロジェクト: dionimf/stoq
    def test_create_inventory(self):
        branch = self.create_branch()
        # A category so that we can filter the products we want in the
        # inventory
        cat = self.create_sellable_category()

        #  First, lets create some sellables for our test
        # One storable with stock (it should be in the inventory)
        storable1 = self.create_storable(branch=branch, stock=10)
        storable1.product.sellable.category = cat

        # One storable without stock (it should NOT be in the inventory)
        storable2 = self.create_storable()
        storable2.product.sellable.category = cat

        # One storable with one batch, and stock (it should be in the inventory)
        storable3 = self.create_storable()
        storable3.is_batch = True
        storable3.product.sellable.category = cat
        batch1 = self.create_storable_batch(storable3, u'123')
        storable3.increase_stock(3, branch, batch=batch1,
                                 type=0, object_id=None, unit_cost=10)

        # One storable with one batch and a stock item (but without stock).
        # it should be on the inventory
        storable4 = self.create_storable()
        storable4.is_batch = True
        storable4.product.sellable.category = cat
        batch2 = self.create_storable_batch(storable4, u'124')
        storable4.increase_stock(1, branch, batch=batch2,
                                 type=0, object_id=None, unit_cost=10)
        storable4.decrease_stock(1, branch, batch=batch2,
                                 type=0, object_id=None)

        # Then, lets open the inventory
        responsible = self.create_user()
        query = Sellable.category == cat
        inventory = Inventory.create_inventory(self.store, branch, responsible, query)

        self.assertEquals(inventory.branch, branch)
        self.assertEquals(inventory.responsible, responsible)

        # There should be only 3 items in the inventory
        items = inventory.get_items()
        self.assertEqual(items.count(), 3)
        self.assertEqual(set(i.product for i in items),
                         set([storable1.product,
                              storable3.product,
                              storable4.product]))

        # Use this examples to also test get_inventory_data
        data = list(inventory.get_inventory_data())
        self.assertEquals(len(data), 3)

        # each row should have 5 items
        row = data[0]
        self.assertEquals(len(row), 5)

        self.assertEquals(set(i[0] for i in data), set(items))
        self.assertEquals(set(i[1] for i in data),
                          set([storable1, storable3, storable4]))
        self.assertEquals(set(i[4] for i in data),
                          set([None, batch1, batch2]))