Example #1
0
 def select_wizard(store, model=None):
     if not model:
         return
     has_workorders = not WorkOrder.find_by_sale(store,
                                                 model).is_empty()
     if has_workorders:
         return OpticalSaleQuoteWizard
Example #2
0
 def print_quote_details(self, model, payments_created=False):
     msg = _('Would you like to print the quote details now?')
     # We can only print the details if the quote was confirmed.
     if yesno(msg, Gtk.ResponseType.YES, _("Print quote details"),
              _("Don't print")):
         orders = WorkOrder.find_by_sale(self.model.store, self.model)
         print_report(OpticalWorkOrderReceiptReport, list(orders))
Example #3
0
 def print_quote_details(self, model, payments_created=False):
     msg = _('Would you like to print the quote details now?')
     # We can only print the details if the quote was confirmed.
     if yesno(msg, gtk.RESPONSE_YES,
              _("Print quote details"), _("Don't print")):
         orders = WorkOrder.find_by_sale(self.model.store, self.model)
         print_report(OpticalWorkOrderReceiptReport, list(orders))
Example #4
0
    def _on_PrintReportEvent(self, report_class, *args, **kwargs):
        if issubclass(report_class, SaleOrderReport):
            sale = args[0]
            store = sale.store
            workorders = list(WorkOrder.find_by_sale(store, sale))
            if len(workorders):
                print_report(OpticalWorkOrderReceiptReport, workorders)
                return True

        return False
Example #5
0
    def _on_PrintReportEvent(self, report_class, *args, **kwargs):
        if issubclass(report_class, SaleOrderReport):
            sale = args[0]
            store = sale.store
            workorders = list(WorkOrder.find_by_sale(store, sale))
            if len(workorders):
                print_report(OpticalWorkOrderReceiptReport, workorders)
                return True

        return False
Example #6
0
    def on_Confirm__activate(self, action):
        selected = self.results.get_selected()

        # If there are unfinished workorders associated with the sale, we
        # cannot print the coupon yet. Instead lets just create the payments.
        workorders = WorkOrder.find_by_sale(self.store, selected.sale)
        if not all(wo.can_close() for wo in workorders):
            self._create_sale_payments(selected)
        else:
            self._confirm_order(selected)
        self._update_total()
Example #7
0
    def on_Confirm__activate(self, action):
        selected = self.results.get_selected()
        query = WorkOrder.status != WorkOrder.STATUS_WORK_FINISHED

        # If there are unfinished workorders associated with the sale, we
        # cannot print the coupon yet. Instead lets just create the payments.
        unfinished = WorkOrder.find_by_sale(self.store, selected.sale).find(query)
        if not unfinished.is_empty():
            self._create_sale_payments(selected)
        else:
            self._confirm_order(selected)
        self._update_total()
Example #8
0
    def _confirm_order(self, order_view):
        if self.check_open_inventory():
            return

        store = api.new_store()
        sale = store.fetch(order_view.sale)
        expire_date = sale.expire_date

        if (sale.status == Sale.STATUS_QUOTE and expire_date
                and expire_date.date() < date.today()
                and not yesno(_("This quote has expired. Confirm it anyway?"),
                              Gtk.ResponseType.YES, _("Confirm quote"),
                              _("Don't confirm"))):
            store.close()
            return

        missing = get_missing_items(sale, store)

        if missing:
            retval = run_dialog(MissingItemsDialog, self, sale, missing)
            if retval:
                self.refresh()
            store.close()
            return

        coupon = self._open_coupon(sale)
        if not coupon:
            store.close()
            return
        subtotal = coupon.add_sale_items(sale)
        try:
            if coupon.confirm(sale, store, subtotal=subtotal):
                workorders = WorkOrder.find_by_sale(store, sale)
                for order in workorders:
                    # at this poing, orders could be either FINISHED or
                    # DELIVERED (closed). If it is finished, we should close it
                    # (mark delivered) ...
                    if order.can_close():
                        order.close()
                    else:
                        # ... but if it didn't need closing, it should already
                        # be delivered.
                        assert order.is_finished()
                store.commit()
                self.refresh()
            else:
                coupon.cancel()
        except SellError as err:
            warning(str(err))
        except ModelDataError as err:
            warning(str(err))

        store.close()
Example #9
0
    def _confirm_order(self, order_view):
        if self.check_open_inventory():
            return

        store = api.new_store()
        sale = store.fetch(order_view.sale)
        expire_date = sale.expire_date

        if (sale.status == Sale.STATUS_QUOTE and
            expire_date and expire_date.date() < date.today() and
            not yesno(_("This quote has expired. Confirm it anyway?"),
                      gtk.RESPONSE_YES,
                      _("Confirm quote"), _("Don't confirm"))):
            store.close()
            return

        missing = get_missing_items(sale, store)

        if missing:
            retval = run_dialog(MissingItemsDialog, self, sale, missing)
            if retval:
                self.refresh()
            store.close()
            return

        coupon = self._open_coupon(sale)
        if not coupon:
            store.close()
            return
        subtotal = self._add_sale_items(sale, coupon)
        try:
            if coupon.confirm(sale, store, subtotal=subtotal):
                workorders = WorkOrder.find_by_sale(store, sale)
                for order in workorders:
                    # at this poing, orders could be either FINISHED or
                    # DELIVERED (closed). If it is finished, we should close it
                    # (mark delivered) ...
                    if order.can_close():
                        order.close()
                    else:
                        # ... but if it didn't need closing, it should already
                        # be delivered.
                        assert order.is_finished()
                store.commit()
                self.refresh()
            else:
                coupon.cancel()
        except SellError as err:
            warning(str(err))
        except ModelDataError as err:
            warning(str(err))

        store.close()
Example #10
0
    def on_Confirm__activate(self, action):
        selected = self.results.get_selected()
        query = WorkOrder.status != WorkOrder.STATUS_WORK_FINISHED

        # If there are unfinished workorders associated with the sale, we
        # cannot print the coupon yet. Instead lets just create the payments.
        unfinished = WorkOrder.find_by_sale(self.store,
                                            selected.sale).find(query)
        if not unfinished.is_empty():
            self._create_sale_payments(selected)
        else:
            self._confirm_order(selected)
        self._update_total()
Example #11
0
    def _fill_wo_categories_combo(self):
        wo_categories = list(self.store.find(WorkOrderCategory))
        self.wo_categories.color_attribute = 'color'

        self.wo_categories.prefill(
            api.for_combo(wo_categories, empty=_("No category")))
        self.wo_categories.set_sensitive(len(wo_categories))

        # We can use any work order, since all workorders in the same sale are
        # sharing the same category.
        workorder = WorkOrder.find_by_sale(self.store, self.model).any()
        if workorder and workorder.category:
            self.wo_categories.select(workorder.category)
Example #12
0
    def _fill_wo_categories_combo(self):
        wo_categories = list(self.store.find(WorkOrderCategory))
        self.wo_categories.color_attribute = 'color'

        self.wo_categories.prefill(
            api.for_combo(wo_categories, empty=_("No category")))
        self.wo_categories.set_sensitive(len(wo_categories))

        # We can use any work order, since all workorders in the same sale are
        # sharing the same category.
        workorder = WorkOrder.find_by_sale(self.store, self.model).any()
        if workorder and workorder.category:
            self.wo_categories.select(workorder.category)
Example #13
0
    def test_find_by_sale(self):
        workorder1 = self.create_workorder()
        workorder2 = self.create_workorder()
        workorder3 = self.create_workorder()

        sale = self.create_sale()
        workorder1.sale = sale
        workorder2.sale = sale

        workorders = list(WorkOrder.find_by_sale(self.store, sale))
        self.assertEquals(len(workorders), 2)
        self.assertIn(workorder1, workorders)
        self.assertIn(workorder2, workorders)
        self.assertNotIn(workorder3, workorders)
Example #14
0
    def test_find_by_sale(self):
        workorder1 = self.create_workorder()
        workorder2 = self.create_workorder()
        workorder3 = self.create_workorder()

        sale = self.create_sale()
        workorder1.sale = sale
        workorder2.sale = sale

        workorders = list(WorkOrder.find_by_sale(self.store, sale))
        self.assertEquals(len(workorders), 2)
        self.assertIn(workorder1, workorders)
        self.assertIn(workorder2, workorders)
        self.assertNotIn(workorder3, workorders)
Example #15
0
    def edit(self, sale):
        with api.new_store() as store:
            sale = store.fetch(sale)

            # If we have work orders on the sale (the sale is a pre-sale), we need
            # to run WorkOrderQuoteWizard instead of SaleQuoteWizard
            has_workorders = not WorkOrder.find_by_sale(store, sale).is_empty()
            if has_workorders:
                wizard = WorkOrderQuoteWizard
            else:
                wizard = SaleQuoteWizard
            self.run_dialog(wizard, store, sale)

        if store.committed:
            self.emit('model-edited', sale)
Example #16
0
    def edit(self, sale):
        with api.new_store() as store:
            sale = store.fetch(sale)

            # If we have work orders on the sale (the sale is a pre-sale), we need
            # to run WorkOrderQuoteWizard instead of SaleQuoteWizard
            has_workorders = not WorkOrder.find_by_sale(store, sale).is_empty()
            if has_workorders:
                wizard = WorkOrderQuoteWizard
            else:
                wizard = SaleQuoteWizard
            self.run_dialog(wizard, store, sale)

        if store.committed:
            self.emit('model-edited', sale)
Example #17
0
    def _fill_wo_categories_combo(self):
        wo_categories = list(self.store.find(WorkOrderCategory))
        self.wo_categories.color_attribute = 'color'

        if len(wo_categories) > 0:
            items = [(category.get_description(), category)
                     for category in wo_categories]
            items = locale_sorted(items, key=operator.itemgetter(0))
            items.insert(0, ('No category', None))
            self.wo_categories.prefill(items)
            self.wo_categories.set_sensitive(True)

        workorders = WorkOrder.find_by_sale(self.store, self.model)
        if workorders:
            # We only need the first workorder, because all workorders in the
            # same sale are sharing the same category.
            self.wo_categories.select(workorders[0].category)
Example #18
0
    def _fill_wo_categories_combo(self):
        wo_categories = list(self.store.find(WorkOrderCategory))
        self.wo_categories.color_attribute = 'color'

        if len(wo_categories) > 0:
            items = [(category.get_description(), category)
                     for category in wo_categories]
            items = locale_sorted(items, key=operator.itemgetter(0))
            items.insert(0, ('No category', None))
            self.wo_categories.prefill(items)
            self.wo_categories.set_sensitive(True)

        # We can use any work order, since all workorders in the same sale are
        # sharing the same category.
        workorder = WorkOrder.find_by_sale(self.store, self.model).any()
        if workorder and workorder.category:
            self.wo_categories.select(workorder.category)
Example #19
0
    def _confirm_order(self, order_view):
        if self.check_open_inventory():
            return

        store = api.new_store()
        sale = store.fetch(order_view.sale)
        expire_date = sale.expire_date

        if (sale.status == Sale.STATUS_QUOTE and
            expire_date and expire_date.date() < date.today() and
            not yesno(_("This quote has expired. Confirm it anyway?"),
                      gtk.RESPONSE_YES,
                      _("Confirm quote"), _("Don't confirm"))):
            store.close()
            return

        missing = get_missing_items(sale, store)

        if missing:
            retval = run_dialog(MissingItemsDialog, self, sale, missing)
            if retval:
                self.refresh()
            store.close()
            return

        coupon = self._open_coupon()
        if not coupon:
            store.close()
            return
        subtotal = self._add_sale_items(sale, coupon)
        try:
            if coupon.confirm(sale, store, subtotal=subtotal):
                workorders = WorkOrder.find_by_sale(store, sale)
                for order in workorders:
                    order.close()
                store.commit()
                self.refresh()
            else:
                coupon.cancel()
        except SellError as err:
            warning(str(err))
        except ModelDataError as err:
            warning(str(err))

        store.close()
Example #20
0
    def _create_ui(self):
        new_button = gtk.Button(gtk.STOCK_NEW)
        new_button.set_use_stock(True)
        new_button.set_relief(gtk.RELIEF_NONE)
        new_button.show()
        new_button.connect('clicked', self._on_new_work_order__clicked)
        self.work_orders_nb.set_action_widget(new_button, gtk.PACK_END)
        self.new_tab_button = new_button

        saved_orders = list(WorkOrder.find_by_sale(self.store, self.model))
        # This sale does not have any work order yet. Create the first for it
        if not saved_orders:
            self._add_work_order(self._create_work_order())
            return

        # This sale already have some orders, restore them so the user can edit
        for order in saved_orders:
            self._add_work_order(order)
Example #21
0
    def _create_ui(self):
        new_button = Gtk.Button(Gtk.STOCK_NEW)
        new_button.set_use_stock(True)
        new_button.set_relief(Gtk.ReliefStyle.NONE)
        new_button.show()
        new_button.connect('clicked', self._on_new_work_order__clicked)
        self.work_orders_nb.set_action_widget(new_button, Gtk.PackType.END)
        self.new_tab_button = new_button

        saved_orders = list(WorkOrder.find_by_sale(self.store, self.model))
        # This sale does not have any work order yet. Create the first for it
        if not saved_orders:
            self._add_work_order(self._create_work_order())
            return

        # This sale already have some orders, restore them so the user can edit
        for order in saved_orders:
            self._add_work_order(order)
Example #22
0
    def edit(self, sale_view=None):
        if sale_view is None:
            sale_view = self.sales.get_selected()
        store = api.new_store()
        sale = store.fetch(sale_view.sale)

        # If we have work orders on the sale (the sale is a pre-sale), we need
        # to run WorkOrderQuoteWizard instead of SaleQuoteWizard
        has_workorders = not WorkOrder.find_by_sale(store, sale).is_empty()
        if has_workorders:
            wizard = WorkOrderQuoteWizard
        else:
            wizard = SaleQuoteWizard
        model = run_dialog(wizard, self.parent, store, sale)
        retval = store.confirm(model)
        store.close()

        if retval:
            self.emit('sale-edited', retval)
Example #23
0
    def edit(self, sale_view=None):
        if sale_view is None:
            sale_view = self.sales.get_selected()
        store = api.new_store()
        sale = store.fetch(sale_view.sale)

        # If we have work orders on the sale (the sale is a pre-sale), we need
        # to run WorkOrderQuoteWizard instead of SaleQuoteWizard
        has_workorders = not WorkOrder.find_by_sale(store, sale).is_empty()
        if has_workorders:
            wizard = WorkOrderQuoteWizard
        else:
            wizard = SaleQuoteWizard
        model = run_dialog(wizard, self.parent, store, sale)
        retval = store.confirm(model)
        store.close()

        if retval:
            self.emit('sale-edited', retval)
Example #24
0
 def select_wizard(store, model=None):
     if not model:
         return
     has_workorders = not WorkOrder.find_by_sale(store, model).is_empty()
     if has_workorders:
         return OpticalSaleQuoteWizard