Example #1
0
    def run_wizard(cls, parent):
        """Run the wizard to create a product

        This will run the wizard and after finishing, ask if the user
        wants to create another product alike. The product will be
        cloned and `stoqlib.gui.editors.producteditor.ProductEditor`
        will run as long as the user chooses to create one alike
        """
        with api.new_store() as store:
            rv = run_dialog(cls, parent, store)

        if rv:
            inner_rv = rv

            while yesno(_("Would you like to register another product alike?"),
                        gtk.RESPONSE_NO, _("Yes"), _("No")):
                with api.new_store() as store:
                    template = store.fetch(rv)
                    inner_rv = run_dialog(ProductEditor, parent, store,
                                          product_type=template.product_type,
                                          template=template)

                if not inner_rv:
                    break

        # We are insterested in the first rv that means that at least one
        # obj was created.
        return rv
Example #2
0
 def search_products(self):
     with api.new_store() as store:
         profile = api.get_current_user(store).profile
         can_create = (profile.check_app_permission('admin') or
                       profile.check_app_permission('purchase'))
         run_dialog(ProductSearch, None, store, hide_footer=True, hide_toolbar=not can_create,
                    hide_cost_column=not can_create)
Example #3
0
    def _delete_account(self, account_view):
        store = api.new_store()
        account = store.fetch(account_view.account)
        methods = PaymentMethod.get_by_account(store, account)
        if methods.count() > 0:
            if not yesno(
                _('This account is used in at least one payment method.\n'
                  'To be able to delete it the payment methods needs to be'
                  're-configured first'), gtk.RESPONSE_NO,
                _("Configure payment methods"), _("Keep account")):
                store.close()
                return
        elif not yesno(
            _('Are you sure you want to remove account "%s" ?') % (
                (account_view.description, )), gtk.RESPONSE_NO,
            _("Remove account"), _("Keep account")):
            store.close()
            return

        if account_view.id in self._pages:
            account_page = self._pages[account_view.id]
            self._close_page(account_page)

        self.accounts.remove(account_view)
        self.accounts.flush()

        imbalance = api.sysparam(store).IMBALANCE_ACCOUNT
        for method in methods:
            method.destination_account = imbalance

        account.remove(store)
        store.commit(close=True)
Example #4
0
    def on_SalesCancel__activate(self, action):
        sale_view = self.results.get_selected()
        can_cancel = api.sysparam.get_bool('ALLOW_CANCEL_LAST_COUPON')
        if can_cancel and ECFIsLastSaleEvent.emit(sale_view.sale):
            info(_("That is last sale in ECF. Return using the menu "
                   "ECF - Cancel Last Document"))
            return

        store = api.new_store()
        sale = store.fetch(sale_view.sale)
        msg_text = _(u"This will cancel the sale, Are you sure?")
        model = SaleComment(store=store, sale=sale,
                            author=api.get_current_user(store))

        retval = self.run_dialog(
            NoteEditor, store, model=model, attr_name='comment',
            message_text=msg_text, label_text=_(u"Reason"),
            mandatory=True, ok_button_label=_(u"Cancel sale"),
            cancel_button_label=_(u"Don't cancel"))

        if not retval:
            store.rollback()
            return

        sale.cancel()
        store.commit(close=True)
        self.refresh()
Example #5
0
 def _edit_item(self, item):
     store = api.new_store()
     parameter = store.fetch(item)
     retval = run_dialog(SystemParameterEditor, self, store, parameter)
     if store.confirm(retval):
         self.results.update(item)
     store.close()
Example #6
0
 def on_LoanClose__activate(self, action):
     if self.check_open_inventory():
         return
     store = api.new_store()
     model = self.run_dialog(CloseLoanWizard, store)
     store.confirm(model)
     store.close()
Example #7
0
    def open_till(self):
        """Opens the till
        """
        try:
            current_till = Till.get_current(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
Example #8
0
 def _create_client(self):
     store = api.new_store()
     client = run_person_role_dialog(ClientEditor, self.wizard, store, None)
     store.confirm(client)
     client = self.store.fetch(client)
     store.close()
     if not client:
         return
     if len(self.client) == 0:
         self._fill_clients_combo()
         return
     clients = self.client.get_model_items().values()
     if client in clients:
         if client.is_active:
             self.client.select(client)
         else:
             # remove client from combo
             self.client.select_item_by_data(client)
             iter = self.client.get_active_iter()
             model = self.client.get_model()
             model.remove(iter)
             # just in case the inactive client was selected before.
             self.client.select_item_by_position(0)
     elif client.is_active:
         self.client.append_item(client.person.name, client)
         self.client.select(client)
     self._update_widgets()
Example #9
0
 def _run_category_editor(self, category=None):
     with api.new_store() as store:
         rv = run_dialog(WorkOrderCategoryEditor, self, store, category,
                         visual_mode=self.visual_mode)
     if rv:
         self._fill_categories_combo()
         self.category.select(self.store.fetch(rv))
Example #10
0
    def _send_selected_items_to_supplier(self):
        orders = self.results.get_selected_rows()
        valid_order_views = [
            order for order in orders
            if order.status == PurchaseOrder.ORDER_PENDING]

        if not valid_order_views:
            warning(_("There are no pending orders selected."))
            return

        msg = stoqlib_ngettext(
            _("The selected order will be marked as sent."),
            _("The %d selected orders will be marked as sent.")
            % len(valid_order_views),
            len(valid_order_views))
        confirm_label = stoqlib_ngettext(_("Confirm order"),
                                         _("Confirm orders"),
                                         len(valid_order_views))
        if not yesno(msg, gtk.RESPONSE_YES, confirm_label, _("Don't confirm")):
            return

        with api.new_store() as store:
            for order_view in valid_order_views:
                order = store.fetch(order_view.purchase)
                order.confirm()
        self.refresh()
        self.select_result(orders)
    def _receive(self):
        with api.new_store() as store:
            till = Till.get_current(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()
Example #12
0
 def _run_quote_editor(self):
     store = api.new_store()
     selected = store.fetch(self.search.results.get_selected().purchase)
     retval = run_dialog(QuoteFillingDialog, self.wizard, selected, store)
     store.confirm(retval)
     store.close()
     self._update_view()
Example #13
0
 def _open_production_order(self, order=None):
     store = api.new_store()
     order = store.fetch(order)
     retval = self.run_dialog(ProductionWizard, store, order)
     store.confirm(retval)
     store.close()
     self.refresh()
Example #14
0
 def _run_client_editor(self, client=None):
     with api.new_store() as store:
         rv = run_person_role_dialog(ClientEditor, self, store, client,
                                     visual_mode=self.visual_mode)
     if rv:
         self._fill_clients_combo()
         self.client.select(rv.id)
Example #15
0
 def _delete_model(self, model):
     if self._reuse_store:
         self._delete_with_transaction(model, self._reuse_store)
     else:
         store = api.new_store()
         self._delete_with_transaction(model, store)
         store.commit(close=True)
Example #16
0
    def render_GET(self, resource):
        start = datetime.date.fromtimestamp(float(resource.args['start'][0]))
        end = datetime.date.fromtimestamp(float(resource.args['end'][0]))

        store = api.new_store()
        day_events = {}
        if resource.args.get('in_payments', [''])[0] == 'true':
            self._collect_inpayments(start, end, day_events, store)
        if resource.args.get('out_payments', [''])[0] == 'true':
            self._collect_outpayments(start, end, day_events, store)
        if resource.args.get('purchase_orders', [''])[0] == 'true':
            self._collect_purchase_orders(start, end, day_events, store)
        if resource.args.get('client_calls', [''])[0] == 'true':
            self._collect_client_calls(start, end, day_events, store)
        if resource.args.get('client_birthdays', [''])[0] == 'true':
            self._collect_client_birthdays(start, end, day_events, store)
        if resource.args.get('work_orders', [''])[0] == 'true':
            self._collect_work_orders(start, end, day_events, store)

        # When grouping, events of the same type will be shown as only one, to
        # save space.
        group = resource.args.get('group', [''])[0] == 'true'
        events = self._summarize_events(day_events, group)
        store.close()
        return json.dumps(events)
Example #17
0
File: pos.py Project: pkaislan/stoq
    def on_WorkOrderClose__activate(self, action):
        if self.check_open_inventory():
            return

        if self._current_store:
            store = self._current_store
            store.savepoint('before_run_search_workorder')
        else:
            store = api.new_store()

        rv = self.run_dialog(
            WorkOrderFinishedSearch, store, double_click_confirm=True)
        if rv:
            work_order = rv.work_order
            for item in work_order.order_items:
                self.add_sale_item(
                    TemporarySaleItem(
                        sellable=item.sellable,
                        quantity=item.quantity,
                        quantity_decreased=item.quantity_decreased,
                        price=item.price,
                        can_remove=False))
            work_order.close()
            if self._suggested_client is None:
                self._suggested_client = work_order.client
            self._current_store = store
        elif self._current_store:
            store.rollback_to_savepoint('before_run_search_workorder')
        else:
            store.rollback(close=True)
Example #18
0
File: pos.py Project: pkaislan/stoq
    def on_NewTrade__activate(self, action):
        if self._trade:
            if yesno(
                    _("There is already a trade in progress... Do you "
                      "want to cancel it and start a new one?"),
                    gtk.RESPONSE_NO, _("Cancel trade"), _("Finish trade")):
                self._clear_trade(remove=True)
            else:
                return

        if self._current_store:
            store = self._current_store
            store.savepoint('before_run_wizard_saletrade')
        else:
            store = api.new_store()

        trade = self.run_dialog(SaleTradeWizard, store)
        if trade:
            self._trade = trade
            self._current_store = store
        elif self._current_store:
            store.rollback_to_savepoint('before_run_wizard_saletrade')
        else:
            store.rollback(close=True)

        self._show_trade_infobar(trade)
Example #19
0
    def _edit(self, payable_views):
        with api.new_store() as store:
            order = store.fetch(payable_views[0].purchase)
            run_dialog(PurchasePaymentsEditor, self, store, order)

        if store.committed:
            self.refresh()
Example #20
0
    def _pay(self, payable_views):
        """
        Pay a list of items from a payable_views, note that
        the list of payable_views must reference the same order
        @param payables_views: a list of payable_views
        """
        assert self._can_pay(payable_views)

        # Do not allow confirming the payment if the purchase was not
        # completely received.
        purchase_order = payable_views[0].purchase

        if (purchase_order and
            api.sysparam.get_bool('BLOCK_INCOMPLETE_PURCHASE_PAYMENTS') and
            not purchase_order.status == PurchaseOrder.ORDER_CLOSED):

            return warning(_("Can't confirm the payment if the purchase "
                             "is not completely received yet."))

        with api.new_store() as store:
            payments = [store.fetch(view.payment) for view in payable_views]

            run_dialog(PurchasePaymentConfirmSlave, self, store,
                       payments=payments)

        if store.committed:
            # We need to refresh the whole list as the payment(s) can possibly
            # disappear for the selected view
            self.refresh()

        self._update_widgets()
Example #21
0
 def on_further_details_button__clicked(self, *args):
     store = api.new_store()
     model = store.fetch(self.model)
     run_person_role_dialog(ClientEditor, self, store,
                            model, visual_mode=True)
     store.confirm(False)
     store.close()
Example #22
0
 def on_ChangePassword__activate(self, action):
     from stoqlib.gui.slaves.userslave import PasswordEditor
     store = api.new_store()
     user = api.get_current_user(store)
     retval = run_dialog(PasswordEditor, self, store, user)
     store.confirm(retval)
     store.close()
Example #23
0
    def run_editor(self, obj=None):
        store = api.new_store()
        product = self.run_dialog(self.editor_class, self, store,
                                  store.fetch(obj), visual_mode=self._read_only)

        # This means we are creating a new product. After that, add the
        # current supplier as the supplier for this product
        if (obj is None and product
            and not product.is_supplied_by(self._supplier)):
            ProductSupplierInfo(store=store,
                                supplier=store.fetch(self._supplier),
                                product=product,
                                base_cost=product.sellable.cost,
                                is_main_supplier=True)

        if store.confirm(product):
            # If the return value is an ORMObject, fetch it from
            # the right connection
            if isinstance(product, ORMObject):
                product = type(product).get(product.id, store=self.store)

            # If we created a new object, confirm the dialog automatically
            if obj is None:
                self.confirm(product)
                store.close()
                return
        store.close()

        return product
Example #24
0
    def _open_inventory(self):
        with api.new_store() as store:
            rv = self.run_dialog(InventoryOpenEditor, store)

        if rv:
            self.refresh()
            self._update_widgets()
Example #25
0
    def on_SalesCancel__activate(self, action):
        sale_view = self.results.get_selected()
        can_cancel = api.sysparam.get_bool('ALLOW_CANCEL_LAST_COUPON')
        # A plugin (e.g. ECF) can avoid the cancelation of a sale
        # because it wants it to be cancelled using another way
        if can_cancel and SaleAvoidCancelEvent.emit(sale_view.sale):
            return

        store = api.new_store()
        sale = store.fetch(sale_view.sale)
        msg_text = _(u"This will cancel the sale, Are you sure?")
        model = SaleComment(store=store, sale=sale,
                            author=api.get_current_user(store))

        retval = self.run_dialog(
            NoteEditor, store, model=model, attr_name='comment',
            message_text=msg_text, label_text=_(u"Reason"),
            mandatory=True, ok_button_label=_(u"Cancel sale"),
            cancel_button_label=_(u"Don't cancel"))

        if not retval:
            store.rollback()
            return

        sale.cancel()
        store.commit(close=True)
        self.refresh()
Example #26
0
    def on_create_client__clicked(self, button):
        with api.new_store() as store:
            client = run_person_role_dialog(ClientEditor, self, store, None)

        if store.committed:
            self._fill_clients_combo()
            self.client.select(client.id)
Example #27
0
    def edit_order(self, work_order):
        with api.new_store() as store:
            self.run_dialog(WorkOrderEditor, store,
                            model=store.fetch(work_order))

        if store.committed:
            self.emit('model-edited', work_order)
Example #28
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)
            return

        for purchase in PurchaseOrder.find_by_work_order(order.store, order):
            if optical_wo.can_receive_purchase(purchase):
                optical_wo.receive_purchase(purchase, reserve=True)
Example #29
0
 def on_details_button_clicked(self, *args):
     # FIXME: Person editor/slaves are depending on the store being a
     # StoqlibStore. See bug 5012
     with api.new_store() as store:
         selected = self.results.get_selected()
         user = store.fetch(selected.user)
         run_dialog(UserEditor, self, store, user, visual_mode=True)
Example #30
0
    def _work(self):
        selection = self.search.get_selected_item()
        with api.new_store() as store:
            work_order = store.fetch(selection.work_order)
            work_order.work()

        self._update_view(select_item=selection)
Example #31
0
    def _receive_orders(self):
        with api.new_store() as store:
            self.run_dialog(WorkOrderPackageReceiveWizard, store)

        if store.committed:
            self._update_view()
Example #32
0
 def on_SearchQuotes__activate(self, action):
     with api.new_store() as store:
         self.run_dialog(ReceiveQuoteWizard, store)
     self.refresh()
Example #33
0
 def _show_details(self, item):
     with api.new_store() as store:
         model = store.fetch(item.stock_decrease)
         run_dialog(StockDecreaseDetailsDialog, self, store, model)
         store.retval = store.get_pending_count() > 0
Example #34
0
 def __init__(self):
     self.store = api.new_store()
     self.ns = {}
Example #35
0
 def on_ProductionPurchaseQuote__activate(self, action):
     with api.new_store() as store:
         self.run_dialog(ProductionQuoteDialog, store)
Example #36
0
 def on_Reconciliation__activate(self, button):
     with api.new_store() as store:
         self.run_dialog(PurchaseReconciliationWizard, store)
Example #37
0
 def on_ProductsPriceSearch__activate(self, action):
     with api.new_store() as store:
         self.run_dialog(SellableMassEditorDialog, store)
Example #38
0
 def on_Preferences__activate(self, action):
     with api.new_store() as store:
         run_dialog(PreferencesEditor, self, store)
     self._update_toolbar_style()
Example #39
0
 def _open_plugins(self):
     store = api.new_store()
     model = self.app.run_dialog(PluginManagerDialog, store)
     store.confirm(model)
     store.close()
Example #40
0
 def on_CloseInConsignment__activate(self, action):
     with api.new_store() as store:
         self.run_dialog(CloseInConsignmentWizard, store)
Example #41
0
 def _open_payment_methods(self):
     store = api.new_store()
     model = self.app.run_dialog(PaymentMethodsDialog, store)
     store.confirm(model)
     store.close()
Example #42
0
 def _new_user(self):
     store = api.new_store()
     model = run_person_role_dialog(UserEditor, self, store)
     store.confirm(model)
     store.close()
Example #43
0
 def _open_invoice_layouts(self):
     store = api.new_store()
     model = self.app.run_dialog(InvoiceLayoutDialog, store)
     store.confirm(model)
     store.close()
Example #44
0
 def _open_parameters(self):
     store = api.new_store()
     model = self.app.run_dialog(ParameterSearch, store)
     store.confirm(model)
     store.close()
Example #45
0
 def _open_forms(self):
     store = api.new_store()
     model = self.app.run_dialog(FormFieldEditor, store)
     store.confirm(model)
     store.close()
Example #46
0
 def _open_payment_categories(self):
     store = api.new_store()
     model = self.app.run_dialog(PaymentCategoryDialog, store)
     store.confirm(model)
     store.close()
Example #47
0
    def _new_work_order(self):
        with api.new_store() as store:
            self.run_dialog(WorkOrderEditor, store)

        if store.committed:
            self._update_events()
Example #48
0
 def _open_sale_token(self):
     with api.new_store() as store:
         self.app.run_dialog(SaleTokenSearch, store, hide_footer=True)
Example #49
0
 def _on_info_button__clicked(self, entry):
     obj = self.entry.read()
     with api.new_store() as store:
         run_dialog(self.item_info_dialog, self._parent, store,
                    store.fetch(obj))
Example #50
0
    def _new_payment(self, editor):
        with api.new_store() as store:
            self.run_dialog(editor, store)

        if store.committed:
            self._update_events()
Example #51
0
    def send_orders(self, work_order):
        with api.new_store() as store:
            self.run_dialog(WorkOrderPackageSendEditor, store)

        if store.committed:
            self.emit('model-edited', None)
Example #52
0
    def _new_client_call(self):
        with api.new_store() as store:
            self.run_dialog(CallsEditor, store, None, None, Client)

        if store.committed:
            self._update_events()
Example #53
0
 def details(self, work_order):
     with api.new_store() as store:
         self.run_dialog(WorkOrderEditor, store,
                         model=store.fetch(work_order),
                         visual_mode=True)
Example #54
0
    def receive_orders(self, work_order):
        with api.new_store() as store:
            self.run_dialog(WorkOrderPackageReceiveWizard, store)

        if store.committed:
            self.emit('model-edited', None)
Example #55
0
 def _edit_item(self, item):
     store = api.new_store()
     retval = run_dialog(SystemParameterEditor, self, store, item)
     if store.confirm(retval):
         self.results.update(item)
     store.close()
Example #56
0
    def work(self, work_order):
        with api.new_store() as store:
            work_order = store.fetch(work_order)
            work_order.work()

        self.emit('model-edited', work_order)
Example #57
0
    def _send_orders(self):
        with api.new_store() as store:
            self.run_dialog(WorkOrderPackageSendEditor, store)

        if store.committed:
            self._update_view()
Example #58
0
 def _show_payment_categories(self):
     store = api.new_store()
     self.run_dialog(PaymentCategoryDialog, store,
                     self.payment_category_type)
     self._update_filter_items()
     store.close()
Example #59
0
    def _on_OpticalDetails__activate(self, action):
        wo_view = self._current_app.search.get_selected_item()

        with api.new_store() as store:
            work_order = store.fetch(wo_view.work_order)
            run_dialog(OpticalWorkOrderEditor, None, store, work_order)
Example #60
0
 def _run_order_category_dialog(self):
     with api.new_store() as store:
         self.run_dialog(WorkOrderCategoryDialog, store)
     self._update_view()
     self._update_filters()