def __init__(self, user_id, *args, **kwargs):
     super(OrganizationInterface, self).__init__(*args, **kwargs)
     uic.loadUi(self._path, self)
     self.organization = Organizations()
     self.organization_id = self.organization.get_organization_id(user_id)
     self.choice = OrganizationChoice(self.interfaces, self)
     self.interfaces.setCurrentWidget(self.choice)
示例#2
0
    def __init__(self, stacked_widget, *args, **kwargs):
        super(GoodAdder, self).__init__(*args, **kwargs)
        uic.loadUi(self._path, self)
        stacked_widget.addWidget(self)
        self.ancestor = args[0]
        self.organization = Organizations()

        self.add.clicked.connect(self.on_add)
        self.cancel.clicked.connect(self.on_cancel)
示例#3
0
    def __init__(self, stacked_widget, *args, **kwargs):
        super(OrderAdder, self).__init__(*args, **kwargs)
        uic.loadUi(self._path, self)
        stacked_widget.addWidget(self)
        self.ancestor = args[0]
        self.organization = Organizations()
        self.goods = Goods().get_all_goods()
        self.update_data()

        self.add.clicked.connect(self.on_add)
        self.cancel.clicked.connect(self.on_cancel)
        self.good_list.currentRowChanged.connect(self.good_changed)
class OrganizationInterface(QtGui.QWidget):

    _path = ORGANIZATION_INTERFACE

    def __init__(self, user_id, *args, **kwargs):
        super(OrganizationInterface, self).__init__(*args, **kwargs)
        uic.loadUi(self._path, self)
        self.organization = Organizations()
        self.organization_id = self.organization.get_organization_id(user_id)
        self.choice = OrganizationChoice(self.interfaces, self)
        self.interfaces.setCurrentWidget(self.choice)
示例#5
0
    def __init__(self, stacked_widget, *args, **kwargs):
        super(OrderAdder, self).__init__(*args, **kwargs)
        uic.loadUi(self._path, self)
        stacked_widget.addWidget(self)
        self.ancestor = args[0]
        self.organization = Organizations()
        self.goods = Goods().get_all_goods()
        self.update_data()

        self.add.clicked.connect(self.on_add)
        self.cancel.clicked.connect(self.on_cancel)
        self.good_list.currentRowChanged.connect(self.good_changed)
示例#6
0
class GoodAdder(QtGui.QWidget):

    _path = ADD_GOOD_FORM

    def __init__(self, stacked_widget, *args, **kwargs):
        super(GoodAdder, self).__init__(*args, **kwargs)
        uic.loadUi(self._path, self)
        stacked_widget.addWidget(self)
        self.ancestor = args[0]
        self.organization = Organizations()

        self.add.clicked.connect(self.on_add)
        self.cancel.clicked.connect(self.on_cancel)

    def on_cancel(self):
        self.ancestor.on_cancel()

    def on_add(self):
        name = self.name.text()
        price = self.price.text()
        weight = self.weight.text()
        residue = self.residue.text()
        try:
            price = int(price)
            weight = int(weight)
            residue = int(residue)
            self.organization.add_goods(
                name,
                price,
                self.ancestor.organization_id,
                residue,
                weight
            )
            self.on_cancel()
            return
        except Exception as e:
            self.error.setText('Something wrong with good.')
示例#7
0
 def update_info(self):
     orders = Organizations().get_orders(self.organization_id)
     # orders = filter(
     #     lambda x: x['producer_id'] == self.organization_id,
     #     orders
     # )
     # for order in orders:
     #     order.pop('producer_id')
     self.model.clear()
     header_labels = [key for key in orders[0]] if len(orders) > 0 else\
         ['id']
     self.model.setHorizontalHeaderLabels(header_labels)
     row_count = 0
     for order in orders:
         column_count = 0
         for key, value in order.iteritems():
             self.model.setItem(row_count, column_count,
                                QtGui.QStandardItem(str(value)))
             column_count += 1
         row_count += 1
示例#8
0
class OrderAdder(QtGui.QWidget):

    _path = ADD_ORDER_FORM

    def __init__(self, stacked_widget, *args, **kwargs):
        super(OrderAdder, self).__init__(*args, **kwargs)
        uic.loadUi(self._path, self)
        stacked_widget.addWidget(self)
        self.ancestor = args[0]
        self.organization = Organizations()
        self.goods = Goods().get_all_goods()
        self.update_data()

        self.add.clicked.connect(self.on_add)
        self.cancel.clicked.connect(self.on_cancel)
        self.good_list.currentRowChanged.connect(self.good_changed)

    def on_cancel(self):
        self.ancestor.on_cancel()

    def on_add(self):
        try:
            selected_good = self.goods[self.good_list.currentRow() - 1]
            good_id = selected_good['id']
            count = int(self.count.text())
            if count > selected_good['residue']:
                self.error.setText('Wrong good count.')
            else:
                self.organization.add_order(self.ancestor.organization_id,
                                            good_id, count)
            Goods().reduce(good_id, count)
        except Exception as e:
            self.error.setText('Something wrong with data.')
        finally:
            self.update_data()

    def update_data(self):
        self.good_list.clear()
        self.goods = Goods().get_all_goods()
        writen_keys = False
        for good in self.goods:
            values = []
            keys = []
            for key, value in good.iteritems():
                if key != 'producer_id':
                    keys.append(key)
                    values.append(str(value))
            if not writen_keys:
                writen_keys = True
                self.good_list.addItem('\t '.join(keys))
            self.good_list.addItem('\t'.join(values))

    def good_changed(self, index):
        if index == -1:
            return
        try:
            self.error.setText('')
            if index <= 0:
                raise ValueError
            self.good_id.setText(str(self.goods[index - 1]['id']))
        except Exception as e:
            self.error.setText('Do not choose this option.')
示例#9
0
class OrderAdder(QtGui.QWidget):

    _path = ADD_ORDER_FORM

    def __init__(self, stacked_widget, *args, **kwargs):
        super(OrderAdder, self).__init__(*args, **kwargs)
        uic.loadUi(self._path, self)
        stacked_widget.addWidget(self)
        self.ancestor = args[0]
        self.organization = Organizations()
        self.goods = Goods().get_all_goods()
        self.update_data()

        self.add.clicked.connect(self.on_add)
        self.cancel.clicked.connect(self.on_cancel)
        self.good_list.currentRowChanged.connect(self.good_changed)

    def on_cancel(self):
        self.ancestor.on_cancel()

    def on_add(self):
        try:
            selected_good = self.goods[self.good_list.currentRow() - 1]
            good_id = selected_good['id']
            count = int(self.count.text())
            if count > selected_good['residue']:
                self.error.setText('Wrong good count.')
            else:
                self.organization.add_order(
                    self.ancestor.organization_id,
                    good_id,
                    count
                )
            Goods().reduce(good_id, count)
        except Exception as e:
            self.error.setText('Something wrong with data.')
        finally:
            self.update_data()

    def update_data(self):
        self.good_list.clear()
        self.goods = Goods().get_all_goods()
        writen_keys = False
        for good in self.goods:
            values = []
            keys = []
            for key, value in good.iteritems():
                if key != 'producer_id':
                    keys.append(key)
                    values.append(str(value))
            if not writen_keys:
                writen_keys = True
                self.good_list.addItem('\t '.join(keys))
            self.good_list.addItem('\t'.join(values))

    def good_changed(self, index):
        if index == -1:
            return
        try:
            self.error.setText('')
            if index <= 0:
                raise ValueError
            self.good_id.setText(str(self.goods[index - 1]['id']))
        except Exception as e:
            self.error.setText('Do not choose this option.')