示例#1
0
    def _create_receiving_order(self):
        supplier_id = self.purchases[0].supplier_id
        branch = self.purchases[0].branch

        # If the receiving is for another branch, we need a temporary identifier
        temporary_identifier = None
        if (api.sysparam.get_bool('SYNCHRONIZED_MODE')
                and api.get_current_branch(self.store) != branch):
            temporary_identifier = ReceivingOrder.get_temporary_identifier(
                self.store)

        # We cannot create the model in the wizard since we haven't
        # selected a PurchaseOrder yet which ReceivingOrder depends on
        # Create the order here since this is the first place where we
        # actually have a purchase selected
        receiving_invoice = ReceivingInvoice(
            supplier=supplier_id,
            store=self.store,
            branch=branch,
            station=api.get_current_station(self.store),
            responsible=api.get_current_user(self.store))
        self.wizard.model = self.model = ReceivingOrder(
            identifier=temporary_identifier,
            receiving_invoice=receiving_invoice,
            responsible=receiving_invoice.responsible,
            station=api.get_current_station(self.store),
            invoice_number=None,
            branch=branch,
            store=self.store)

        for row in self.purchases:
            self.model.add_purchase(row.purchase)
示例#2
0
    def _on_WorkOrderStatusChangedEvent(self, order, old_status):
        if old_status == WorkOrder.STATUS_OPENED:
            #Do nothing at this point.
            return

        optical_wo = OpticalWorkOrder.find_by_work_order(order.store, order)
        # If there is no optical WO, nothing to do here
        if optical_wo is None:
            return

        if optical_wo.can_create_purchase():
            with api.new_store() as store:
                rv = run_dialog(OpticalSupplierEditor, None, store, order)
            if not rv:
                # Return None to let the status be changed without creating a purchase order
                return

            order.supplier_order = rv.supplier_order
            optical_wo.create_purchase(order.store.fetch(rv.supplier),
                                       order.store.fetch(rv.item),
                                       rv.is_freebie,
                                       api.get_current_branch(order.store),
                                       api.get_current_station(order.store),
                                       api.get_current_user(order.store))
            return

        for purchase in PurchaseOrder.find_by_work_order(order.store, order):
            if optical_wo.can_receive_purchase(purchase):
                optical_wo.receive_purchase(purchase,
                                            api.get_current_station(
                                                order.store),
                                            api.get_current_user(order.store),
                                            reserve=True)
示例#3
0
    def _create_receiving_order(self):
        # since we will create a new receiving order, we should confirm the
        # purchase first. Note that the purchase may already be confirmed
        if self.model.status in [
                PurchaseOrder.ORDER_PENDING, PurchaseOrder.ORDER_CONSIGNED
        ]:
            self.model.confirm(api.get_current_user(self.store))

        temporary_identifier = None
        if self.wizard.is_for_another_branch():
            temporary_identifier = ReceivingOrder.get_temporary_identifier(
                self.store)

        receiving_invoice = ReceivingInvoice(
            store=self.store,
            supplier=self.model.supplier,
            branch=self.model.branch,
            station=api.get_current_station(self.store),
            responsible=api.get_current_user(self.store))
        receiving_model = ReceivingOrder(
            identifier=temporary_identifier,
            receiving_invoice=receiving_invoice,
            responsible=receiving_invoice.responsible,
            branch=self.model.branch,
            station=api.get_current_station(self.store),
            invoice_number=None,
            store=self.store)
        receiving_model.add_purchase(self.model)

        # Creates ReceivingOrderItem's
        for item in self.model.get_pending_items():
            receiving_model.add_purchase_item(item)

        self.wizard.receiving_model = receiving_model
示例#4
0
    def _update_wizard_model(self):
        wizard_model = self.wizard.model
        if wizard_model:
            # We are replacing the model. Remove old one
            wizard_model.remove()

        sale_view = self.slave.results.get_selected()
        # FIXME: Selecting a sale and then clicking on unknown_sale_check
        # will not really deselect it, not until the results are sensitive
        # again. This should be as simple as 'if sale_view'.
        if sale_view and not self.unknown_sale_check.get_active():
            sale = self.store.fetch(sale_view.sale)
            model = sale.create_sale_return_adapter(
                api.get_current_branch(self.store),
                api.get_current_user(self.store),
                api.get_current_station(self.store))
            for item in model.returned_items:
                _adjust_returned_sale_item(item)
        else:
            assert self._allow_unknown_sales()
            model = ReturnedSale(
                store=self.store,
                responsible=api.get_current_user(self.store),
                branch=api.get_current_branch(self.store),
                station=api.get_current_station(self.store),
            )

        self.wizard.model = model
示例#5
0
    def _open_till(self, store):
        till = Till(store=store,
                    branch=api.get_current_branch(store),
                    station=api.get_current_station(store))
        till.open_till(api.get_current_user(store))

        TillOpenEvent.emit(till=till)
        self.assertEqual(till, Till.get_current(store, api.get_current_station(store)))
        return till
示例#6
0
文件: test_sales.py 项目: romaia/stoq
    def test_print_invoice(self, info, print_sale_invoice, run_dialog, new_store):
        new_store.return_value = self.store

        app = self.create_app(SalesApp, u"sales")
        results = app.main_window.results
        results.select(results[0])

        self.activate(app.main_window.SalesPrintInvoice)
        info.assert_called_once_with(u"There are no invoice printer configured " u"for this station")

        layout = InvoiceLayout(description=u"layout", width=10, height=20, store=self.store)
        printer = InvoicePrinter(
            store=self.store,
            description=u"test invoice",
            layout=layout,
            device_name=u"/dev/lp0",
            station=api.get_current_station(self.store),
        )
        self.activate(app.main_window.SalesPrintInvoice)
        self.assertEquals(print_sale_invoice.call_count, 1)
        args, kwargs = print_sale_invoice.call_args
        invoice, called_printer = args
        self.assertTrue(isinstance(invoice, SaleInvoice))
        self.assertEquals(printer, called_printer)

        results[0].sale.invoice_number = None
        InvoiceField(layout=layout, x=0, y=0, width=1, height=1, field_name=u"INVOICE_NUMBER", store=self.store)
        with mock.patch.object(self.store, "commit"):
            with mock.patch.object(self.store, "close"):
                self.activate(app.main_window.SalesPrintInvoice)
                run_dialog.assert_called_once_with(SaleInvoicePrinterDialog, self.store, results[0].sale, printer)
示例#7
0
文件: test_pos.py 项目: pkaislan/stoq
    def _open_till(self, store):
        till = Till(store=store, station=api.get_current_station(store))
        till.open_till()

        TillOpenEvent.emit(till=till)
        self.assertEquals(till, Till.get_current(store))
        return till
示例#8
0
 def create_model(self, store):
     return DeviceSettings(device_name=None,
                           station=api.get_current_station(store),
                           brand=None,
                           model=None,
                           type=None,
                           store=store)
示例#9
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)
示例#10
0
    def _create_payment(self):
        group = PaymentGroup()
        group.payer = self.client.person

        method = PaymentMethod.get_by_name(self.store, u'credit')
        branch = api.get_current_branch(self.store)

        if self.model.value < 0:
            payment_type = Payment.TYPE_IN
        else:
            payment_type = Payment.TYPE_OUT

        # Set status to PENDING now, to avoid calling set_pending on
        # on_confirm for payments that shoud not have its status changed.
        payment = Payment(store=self.store, open_date=localtoday(),
                          branch=branch,
                          station=api.get_current_station(self.store),
                          status=Payment.STATUS_PENDING,
                          description=self.model.description,
                          value=abs(self.model.value),
                          base_value=abs(self.model.value),
                          due_date=localtoday(),
                          method=method,
                          group=group,
                          category=None,
                          payment_type=payment_type,
                          bill_received=False)
        payment.pay()

        return payment
示例#11
0
    def needs_closing(self):
        """Checks if the last opened till was closed and asks the
        user if he wants to close it

        :returns:
            - CLOSE_TILL_BOTH if both DB and ECF needs closing.
            - CLOSE_TILL_DB if only DB needs closing.
            - CLOSE_TILL_ECF if only ECF needs closing.
            - CLOSE_TILL_NONE if both ECF and DB are consistent (they may be
                  closed, or open for the current day)
        """
        ecf_needs_closing = HasPendingReduceZ.emit()

        last_till = Till.get_last(self.store,
                                  api.get_current_station(self.store))
        if last_till:
            db_needs_closing = last_till.needs_closing()
        else:
            db_needs_closing = False

        if db_needs_closing and ecf_needs_closing:
            return CLOSE_TILL_BOTH
        elif db_needs_closing and not ecf_needs_closing:
            return CLOSE_TILL_DB
        elif ecf_needs_closing and not db_needs_closing:
            return CLOSE_TILL_ECF
        else:
            return CLOSE_TILL_NONE
    def _create_receiving_invoice(self):
        # We only let the user get this far if the receivings selected are for the
        # same branch and supplier
        supplier = self.receivings[0].purchase.supplier
        branch = self.receivings[0].branch

        # If the receiving is for another branch, we need a temporary identifier
        temporary_identifier = None
        if (api.sysparam.get_bool('SYNCHRONIZED_MODE')
                and api.get_current_branch(self.store) != branch):
            temporary_identifier = ReceivingInvoice.get_temporary_identifier(
                self.store)

        group = PaymentGroup(store=self.store, recipient=supplier.person)
        self.wizard.model = self.model = ReceivingInvoice(
            identifier=temporary_identifier,
            supplier=supplier,
            group=group,
            branch=branch,
            store=self.store,
            station=api.get_current_station(self.store),
            responsible=api.get_current_user(self.store))

        for row in self.receivings:
            self.model.add_receiving(row.order)
示例#13
0
    def on_confirm(self):
        till = self.model.till
        # Using api.get_default_store instead of self.store
        # or it will return self.model.till
        last_opened = Till.get_last_opened(
            api.get_default_store(),
            api.get_current_station(api.get_default_store()))
        if (last_opened and last_opened.opening_date.date()
                == till.opening_date.date()):
            warning(_("A till was opened earlier this day."))
            self.retval = False
            return

        try:
            TillOpenEvent.emit(till=till)
        except (TillError, DeviceError) as e:
            warning(str(e))
            self.retval = False
            return

        value = self.proxy.model.value
        if value:
            TillAddCashEvent.emit(till=till, value=value)
            till_entry = till.add_credit_entry(value,
                                               _(u'Initial Cash amount'))
            _create_transaction(self.store, till_entry)
示例#14
0
    def _open_till(self, store):
        till = Till(store=store, station=api.get_current_station(store))
        till.open_till()

        TillOpenEvent.emit(till=till)
        self.assertEquals(till, Till.get_current(store))
        return till
示例#15
0
 def create_model(self, store):
     return DeviceSettings(device_name=None,
                           station=api.get_current_station(store),
                           brand=None,
                           model=None,
                           type=None,
                           store=store)
示例#16
0
    def create_model(self, store):
        till = Till(store=store,
                    branch=api.get_current_branch(store),
                    station=api.get_current_station(store))
        till.open_till(api.get_current_user(store))

        return _TillOpeningModel(till=till, value=currency(0))
示例#17
0
def return_sale(parent, sale, store):
    from stoqlib.gui.wizards.salereturnwizard import SaleReturnWizard

    # A plugin (e.g. ECF) can avoid the cancelation of a sale
    # because it wants it to be cancelled using another way
    if SaleAvoidCancelEvent.emit(sale, Sale.STATUS_RETURNED):
        return

    if sale.can_return():
        need_document = not sysparam.get_bool('ACCEPT_SALE_RETURN_WITHOUT_DOCUMENT')
        if need_document and not sale.get_client_document():
            warning(_('It is not possible to accept a returned sale from clients '
                      'without document. Please edit the client document or change '
                      'the sale client'))
            return

        returned_sale = sale.create_sale_return_adapter(api.get_current_branch(store),
                                                        api.get_current_user(store),
                                                        api.get_current_station(store))
        retval = run_dialog(SaleReturnWizard, parent, store, returned_sale)
    elif sale.can_cancel():
        reason = _(u'Sale cancelled due to client return.')
        retval = cancel_sale(sale, reason)
    else:
        retval = False

    return retval
示例#18
0
    def _receive(self):
        with api.new_store() as store:
            till = Till.get_current(store, api.get_current_station(store))
            assert till

            in_payment = self.results.get_selected()
            payment = store.fetch(in_payment.payment)
            assert self._can_receive(payment)

            retval = run_dialog(SalePaymentConfirmSlave,
                                self,
                                store,
                                payments=[payment],
                                show_till_info=False)
            if not retval:
                return

            try:
                TillAddCashEvent.emit(till=till, value=payment.value)
            except (TillError, DeviceError, DriverError) as e:
                warning(str(e))
                return

            till_entry = till.add_credit_entry(
                payment.value,
                _(u'Received payment: %s') % payment.description)

            TillAddTillEntryEvent.emit(till_entry, store)

        if store.committed:
            self.search.refresh()
示例#19
0
    def open_till(self):
        """Opens the till
        """
        try:
            current_till = Till.get_current(
                self.store, api.get_current_station(self.store))
        except TillError as e:
            warning(str(e))
            return False

        if current_till is not None:
            warning(
                _("You already have a till operation opened. "
                  "Close the current Till and open another one."))
            return False

        store = api.new_store()
        try:
            model = run_dialog(TillOpeningEditor, self._parent, store)
        except TillError as e:
            warning(str(e))
            model = None

        retval = store.confirm(model)
        store.close()
        if retval:
            self._till_status_changed(closed=False, blocked=False)
        return retval
示例#20
0
    def _check_user(self, username, pw_hash):
        username = str(username)
        pw_hash = str(pw_hash)
        # This function is really just a post-validation item.
        default_store = api.get_default_store()
        current_branch = api.get_current_branch(default_store)

        user = LoginUser.authenticate(default_store, username, pw_hash,
                                      current_branch)

        # Dont know why, but some users have this empty. Prevent user from
        # login in, since it will break later
        if not user.profile:
            msg = (_("User '%s' has no profile set, "
                     "but this should not happen.") % user.username + '\n\n' +
                   _("Please contact your system administrator or Stoq team."))
            warning(msg)
            raise LoginError(_("User does not have a profile"))

        user.login(api.get_current_station(default_store))

        # ICurrentUser might already be provided which is the case when
        # creating a new database, thus we need to replace it.
        provide_utility(ICurrentUser, user, replace=True)
        return user
示例#21
0
 def _create_work_order(self):
     return WorkOrder(store=self.store,
                      station=api.get_current_station(self.store),
                      sale=self.model,
                      sellable=None,
                      description=u'',
                      branch=api.get_current_branch(self.store),
                      client=self.model.client)
示例#22
0
 def _get_or_create_quote_group(self, order, store):
     if order is not None:
         quotation = store.find(Quotation, purchase=order).one()
         return quotation.group
     else:
         return QuoteGroup(branch=api.get_current_branch(store),
                           station=api.get_current_station(store),
                           store=store)
示例#23
0
 def setup_cash_payment(self, total=None):
     money_method = PaymentMethod.get_by_name(self.store, u'money')
     total = total or self.wizard.get_total_to_pay()
     try:
         return money_method.create_payment(
             self.model.branch, api.get_current_station(self.store),
             Payment.TYPE_IN, self.model.group, total)
     except PaymentMethodError as err:
         warning(str(err))
示例#24
0
 def _create_model(self, store):
     loan = Loan(responsible=api.get_current_user(store),
                 branch=api.get_current_branch(store),
                 station=api.get_current_station(store),
                 store=store)
     # Temporarily save the client_category, so it works fine with
     # SaleQuoteItemStep
     loan.client_category = None
     return loan
示例#25
0
    def _create_model(self, store):
        if self.receiving_order:
            return StockDecrease.create_for_receiving_order(
                self.receiving_order, api.get_current_branch(store),
                api.get_current_station(store), api.get_current_user(store))

        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,
                                       station=api.get_current_station(store),
                                       status=StockDecrease.STATUS_INITIAL,
                                       cfop_id=cfop_id)
        stock_decrease.invoice.operation_nature = self.title
        return stock_decrease
示例#26
0
 def _create_model(self, store):
     user = api.get_current_user(store)
     source_responsible = store.find(Employee, person=user.person).one()
     dest_branch = Branch.get_active_remote_branches(
         store, api.get_current_branch(store))[0]
     return TransferOrder(branch=api.get_current_branch(store),
                          station=api.get_current_station(store),
                          source_responsible=source_responsible,
                          destination_branch=dest_branch,
                          store=store)
示例#27
0
    def _create_statusbar(self):
        statusbar = ShellStatusbar(self)

        # Set the initial text, the currently logged in user and the actual
        # branch and station.
        user = api.get_current_user(self.store)
        station = api.get_current_station(self.store)
        status_str = "   |   ".join([_("User: %s") % (user.get_description(),), _("Computer: %s") % (station.name,)])
        statusbar.push(0, status_str)
        return statusbar
示例#28
0
 def create_model(self, store):
     till = Till.get_current(self.store,
                             api.get_current_station(self.store))
     return Settable(
         employee=None,
         payment=None,
         # FIXME: should send in consts.now()
         open_date=None,
         till=till,
         balance=till.get_balance(),
         value=currency(0))
示例#29
0
    def _get_till_balance(self):
        """Returns the balance of till operations"""
        try:
            till = Till.get_current(self.store, api.get_current_station(self.store))
        except TillError:
            till = None

        if till is None:
            return currency(0)

        return till.get_balance()
示例#30
0
 def _create_model(self, store):
     supplier_id = sysparam.get_object_id('SUGGESTED_SUPPLIER')
     branch = api.get_current_branch(store)
     group = PaymentGroup(store=store)
     status = PurchaseOrder.ORDER_PENDING
     return PurchaseOrder(supplier_id=supplier_id,
                          responsible=api.get_current_user(store),
                          branch=branch,
                          station=api.get_current_station(store),
                          status=status,
                          group=group,
                          store=store)
 def login(self):
     user = api.get_current_user(self.store) or self.create_user()
     station = api.get_current_station(self.store) or self.create_station()
     station.is_active = True
     rv = self.client.post('/login',
                           data={
                               'user': user.username,
                               'pw_hash': user.pw_hash,
                               'station_name': station.name
                           })
     ans = json.loads(rv.data.decode())
     return ans['token'].replace('JWT', 'Bearer')
示例#32
0
 def _create_model(self, store):
     supplier_id = sysparam.get_object_id('SUGGESTED_SUPPLIER')
     branch = api.get_current_branch(store)
     status = PurchaseOrder.ORDER_QUOTING
     group = PaymentGroup(store=store)
     return PurchaseOrder(supplier_id=supplier_id,
                          branch=branch, status=status,
                          station=api.get_current_station(store),
                          expected_receival_date=None,
                          responsible=api.get_current_user(store),
                          group=group,
                          store=store)
示例#33
0
 def create_model(self, store):
     defect_detected = api.sysparam.get_string('DEFECT_DETECTED_TEMPLATE')
     branch = api.get_current_branch(store)
     return WorkOrder(
         store=store,
         sellable=None,
         description=u'',
         branch=branch,
         station=api.get_current_station(store),
         category=self._default_category,
         defect_detected=defect_detected,
     )
示例#34
0
    def optical_new_purchase(self, work_order):
        with api.new_store() as store:
            order = store.fetch(work_order)
            rv = run_dialog(OpticalSupplierEditor, None, store, order)
            if not rv:
                return False

            order.supplier_order = rv.supplier_order
            optical_wo = OpticalWorkOrder.find_by_work_order(store, order)
            optical_wo.create_purchase(rv.supplier, rv.item, rv.is_freebie,
                                       api.get_current_branch(store),
                                       api.get_current_station(store),
                                       api.get_current_user(store))
示例#35
0
文件: console.py 项目: romaia/stoq
    def populate_namespace(self, bare):
        for table in get_table_types():
            self.ns[table.__name__] = table

        self.ns["store"] = self.store
        self.ns["sysparam"] = api.sysparam
        self.ns["api"] = api

        if not bare:
            self.ns["branch"] = api.get_current_branch(self.store)
            self.ns["station"] = api.get_current_station(self.store)
            self.ns["now"] = datetime.datetime.now
            self.ns["today"] = datetime.date.today

            for name in ("stoqlib.database.runtime", "stoqlib.lib.interfaces", "stoqlib.domain.interfaces"):
                mod = __import__(name, {}, {}, " ")
                self.ns.update(mod.__dict__)
示例#36
0
    def populate_namespace(self, bare):
        for table in get_table_types():
            self.ns[table.__name__] = table

        self.ns['store'] = self.store
        self.ns['sysparam'] = api.sysparam
        self.ns['api'] = api

        if not bare:
            self.ns['branch'] = api.get_current_branch(self.store)
            self.ns['station'] = api.get_current_station(self.store)
            self.ns['now'] = datetime.datetime.now
            self.ns['today'] = datetime.date.today

            for name in ('stoqlib.database.runtime',
                         'stoqlib.lib.interfaces',
                         'stoqlib.domain.interfaces'):
                mod = __import__(name, {}, {}, ' ')
                self.ns.update(mod.__dict__)
示例#37
0
    def process_one(self, data, fields, store):
        if data.parent_account:
            name = _(data.parent_account)
            parent = store.find(Account, description=name).one()
        else:
            parent = None
        account = Account(description=data.description,
                          parent=parent,
                          code=None,
                          station=api.get_current_station(store),
                          account_type=int(data.account_type),
                          store=store)

        if data.bank_number:
            BankAccount(account=account,
                        bank_account=data.bank_account,
                        bank_number=int(data.bank_number),
                        bank_branch=data.bank_branch,
                        store=store)
示例#38
0
文件: sales.py 项目: stoq/stoq
    def _print_invoice(self):
        sale_view = self.results.get_selected()
        assert sale_view
        sale = sale_view.sale
        station = api.get_current_station(self.store)
        printer = InvoicePrinter.get_by_station(station, self.store)
        if printer is None:
            info(_("There are no invoice printer configured for this station"))
            return
        assert printer.layout

        invoice = SaleInvoice(sale, printer.layout)
        if not invoice.has_invoice_number() or sale.invoice.invoice_number:
            print_sale_invoice(invoice, printer)
        else:
            store = api.new_store()
            retval = self.run_dialog(SaleInvoicePrinterDialog, store, store.fetch(sale), printer)
            store.confirm(retval)
            store.close()
示例#39
0
    def create_model(self, store):
        till = Till(store=store, station=api.get_current_station(store))
        till.open_till()

        return _TillOpeningModel(till=till, value=currency(0))
示例#40
0
 def _get_last_document(self, store):
     station = api.get_current_station(store)
     return ECFPrinter.get_last_document(station=station, store=store)