コード例 #1
0
    def test_get_status_name(self):
        self.assertEquals(
            StockDecrease.get_status_name(StockDecrease.STATUS_INITIAL),
            u'Opened')
        self.assertEquals(
            StockDecrease.get_status_name(StockDecrease.STATUS_CONFIRMED),
            u'Confirmed')

        with self.assertRaises(DatabaseInconsistency):
            StockDecrease.get_status_name(-1)
コード例 #2
0
    def create_stock_decrease(self, branch=None, user=None, reason=u'', group=None):
        from stoqlib.domain.stockdecrease import StockDecrease

        employee = self.create_employee()
        cfop = self.create_cfop_data()
        return StockDecrease(responsible=user or get_current_user(self.store),
                             removed_by=employee,
                             branch=branch or get_current_branch(self.store),
                             status=StockDecrease.STATUS_INITIAL,
                             cfop=cfop,
                             reason=reason,
                             group=group,
                             store=self.store)
コード例 #3
0
    def _create_model(self, store):
        if self.receiving_order:
            return StockDecrease.create_for_receiving_order(self.receiving_order)

        branch = api.get_current_branch(store)
        user = api.get_current_user(store)
        employee = user.person.employee
        cfop_id = sysparam.get_object_id('DEFAULT_STOCK_DECREASE_CFOP')
        stock_decrease = StockDecrease(store=store,
                                       responsible=user,
                                       removed_by=employee,
                                       branch=branch,
                                       status=StockDecrease.STATUS_INITIAL,
                                       cfop_id=cfop_id)
        stock_decrease.invoice.operation_nature = self.title
        return stock_decrease
コード例 #4
0
ファイル: patch-02-23.py プロジェクト: leandrorchaves/stoq
def apply_patch(store):
    # Creation of new column in stock_decrease table.
    # And added new Cfop to cfop_data table.
    store.execute("""ALTER TABLE stock_decrease
                   ADD COLUMN cfop_id bigint REFERENCES cfop_data(id);""")

    # Default Cfop should be use in manual stock decrease.
    cfop_data = store.find(CfopData, code=u'5.949').one()
    if not cfop_data:
        cfop_data = CfopData(store=store,
                             code=u"5.949",
                             description=u"Outra saída de mercadoria ou "
                                         u"prestação de serviço não "
                                         u"especificado")

    # Adjusting existing manuals outputs
    for stock_decrease in store.find(StockDecrease):
        stock_decrease.cfop = cfop_data

    retentions = store.execute("""
        SELECT id, quantity, reason, retention_date, product_id, cfop_id
          FROM product_retention_history ORDER BY id;""").get_all()

    # Without retentions, there is no need to create user and employee
    # variables.
    if len(retentions):

        # Default user for migration
        user = get_admin_user(store)
        if user is None:
            users = Person.iselectBy(IUser, is_active=True,
                                     store=store).order_by(Person.id)
            user = users[0]

        # Default employee for migration
        employee = IEmployee(user.person, None)
        if employee is None:
            employees = Person.iselectBy(IEmployee, is_active=True,
                                         store=store).order_by(Person.id)
            employee = employees[0]

        default_branch = sysparam(store).MAIN_COMPANY
        notes = _(u"Stock decrease imported from old retention.")

    history = store.execute("""
        SELECT id, quantity_retained, sellable_id, branch_id
          FROM product_history
         WHERE quantity_retained is not null
          ORDER BY id;""").get_all()

    for i in range(len(retentions)):
        ret = retentions[i]
        hist = history[i]

        product = Product.get(ret[4], store=store)

        branch_id = hist[3]
        if ret[1] != hist[1] or product.sellable.id != hist[2]:
            branch_id = default_branch.id

        decrease = StockDecrease(store=store,
                                 confirm_date=ret[3],
                                 status=StockDecrease.STATUS_CONFIRMED,
                                 reason=ret[2],
                                 notes=notes,
                                 responsible=user,
                                 removed_by=employee,
                                 branch_id=branch_id,
                                 cfop_id=ret[5])

        decrease_item = StockDecreaseItem(store=store,
                                          quantity=ret[1],
                                          sellable=product.sellable)
        decrease.add_item(decrease_item)

        ProductHistory.delete(hist[0], store)
        ProductHistory(branch_id=branch_id, sellable=product.sellable,
                       quantity_decreased=decrease_item.quantity,
                       decreased_date=decrease.confirm_date,
                       store=store)

    store.execute("""ALTER TABLE product_history
                   DROP COLUMN quantity_retained;""")
    store.execute("DROP TABLE product_retention_history;")