Ejemplo n.º 1
0
    def __init__(self):
        super(SalesPage, self).__init__()

        self.manager = SalesManager()

        self.customer = QtGui.QLineEdit()
        self.customer.setReadOnly(True)
        self.customer.setPlaceholderText(
            cbpos.tr.sales_('No customer selected'))

        self.customerBtn = QtGui.QPushButton(cbpos.tr.sales_('Choose'))

        self.tickets = QtGui.QComboBox()
        self.tickets.setEditable(False)

        self.newTicketBtn = QtGui.QPushButton(cbpos.tr.sales_("New"))

        self.ticketTable = TicketTable(self.manager)

        self.currency = QtGui.QComboBox()
        self.currency.setEditable(False)

        self.discount = QtGui.QSpinBox()
        self.discount.setRange(0, 100)
        self.discount.setSingleStep(5)
        self.discount.setSuffix('%')

        self.total = TotalPanel(self.manager)

        self.logo = LogoPanel(self.manager)

        self.catalogLbl = QtGui.QLabel(cbpos.tr.sales_("Choose a product"))
        self.catalog = ProductCatalog()

        self.payBtn = QtGui.QPushButton(cbpos.tr.sales_("Pay"))
        self.cancelBtn = QtGui.QPushButton(cbpos.tr.sales_("Cancel"))

        layout = QtGui.QVBoxLayout()

        topOptions = QtGui.QHBoxLayout()
        topOptions.addWidget(self.customer)
        topOptions.addWidget(self.customerBtn)
        topOptions.addWidget(self.tickets)
        topOptions.addWidget(self.newTicketBtn)

        topOptions.setStretch(0, 1)
        topOptions.setStretch(1, 0)
        topOptions.setStretch(2, 1)
        topOptions.setStretch(3, 0)

        bottomOptions = QtGui.QHBoxLayout()
        bottomOptions.addWidget(self.currency)
        bottomOptions.addStretch(1)
        bottomOptions.addWidget(self.discount)

        bottomOptions.setStretch(0, 1)
        bottomOptions.setStretch(1, 1)
        bottomOptions.setStretch(2, 0)

        buttons = QtGui.QHBoxLayout()
        buttons.addWidget(self.payBtn)
        buttons.addWidget(self.cancelBtn)

        buttons.setStretch(0, 1)
        buttons.setStretch(1, 1)

        size_policy = QtGui.QSizePolicy(QtGui.QSizePolicy.Ignored,
                                        QtGui.QSizePolicy.Ignored)
        size_policy.setVerticalStretch(1)
        size_policy.setHorizontalStretch(1)
        self.payBtn.setSizePolicy(size_policy)
        self.cancelBtn.setSizePolicy(QtGui.QSizePolicy(size_policy))

        left = QtGui.QVBoxLayout()
        left.addLayout(topOptions)
        left.addWidget(self.ticketTable)
        left.addLayout(bottomOptions)

        right = QtGui.QVBoxLayout()
        right.addWidget(self.logo)
        right.addWidget(self.catalogLbl)
        right.addWidget(self.catalog)

        top = QtGui.QHBoxLayout()
        top.addLayout(left)
        top.addLayout(right)

        bottom = QtGui.QHBoxLayout()
        bottom.addWidget(self.total)
        bottom.addLayout(buttons)

        bottom.setStretch(0, 1)
        bottom.setStretch(1, 1)

        layout.addLayout(top)
        layout.addLayout(bottom)

        self.setLayout(layout)

        # Signals
        self.customerBtn.pressed.connect(self.onCustomerButton)
        self.tickets.activated[int].connect(self.onTicketChanged)
        self.newTicketBtn.pressed.connect(self.onNewTicketButton)

        #self.ticketTable.currentCellChanged.connect(self.onTicketlineItemChanged)
        #self.ticketTable.cellDoubleClicked.connect(self.onTicketlineItemActivate)
        self.ticketTable.lineDeleted.connect(self.onTicketlineDeleted)

        self.currency.activated[int].connect(self.onCurrencyChanged)
        self.discount.editingFinished.connect(self.onDiscountValueChanged)

        self.payBtn.pressed.connect(self.onCloseTicketButton)
        self.cancelBtn.pressed.connect(self.onCancelTicketButton)

        self.catalog.childSelected.connect(self.onProductCatalogItemActivate)

        self.setCurrentTicket(None)