Beispiel #1
0
    def _create_or_update_delivery(self):
        delivery_service = sysparam.get_object(self.store, 'DELIVERY_SERVICE')
        delivery_sellable = delivery_service.sellable

        items = [
            item for item in self.slave.klist
            if item.sellable.product is not None
        ]

        if self._delivery is not None:
            model = self._delivery

        else:
            model = CreateDeliveryModel(price=delivery_sellable.price,
                                        recipient=self.model.person)

        rv = run_dialog(CreateDeliveryEditor,
                        self.get_toplevel().get_toplevel(),
                        self.store,
                        model=model,
                        items=items,
                        person_type=Person)

        if not rv:
            return

        self._delivery = rv
        if self._delivery_item:
            self.slave.klist.update(self._delivery_item)
        else:
            self._delivery_item = self.get_order_item(delivery_sellable,
                                                      self._delivery.price, 1)
            self.slave.klist.append(None, self._delivery_item)
Beispiel #2
0
    def _create_or_update_delivery(self):
        delivery_service = sysparam.get_object(self.store, 'DELIVERY_SERVICE')
        delivery_sellable = delivery_service.sellable

        items = [
            item for item in self.slave.klist
            if item.sellable.product is not None
        ]
        if self._delivery is not None:
            model = self._delivery
        else:
            model = CreateDeliveryModel(price=delivery_sellable.price,
                                        client=self.model.client)

        rv = run_dialog(CreateDeliveryEditor,
                        self.get_toplevel().get_toplevel(),
                        self.store,
                        model,
                        sale_items=items)
        if not rv:
            return

        self._delivery = rv
        if self._delivery_item:
            self._delivery_item.price = self._delivery.price
            self._delivery_item.notes = self._delivery.notes
            self._delivery_item.estimated_fix_date = self._delivery.estimated_fix_date
            self.slave.klist.update(self._delivery_item)
        else:
            self._delivery_item = self.get_order_item(delivery_sellable,
                                                      self._delivery.price, 1)
            self.slave.klist.append(None, self._delivery_item)
    def test_wizard_remove_delivery(self, yesno):
        yesno.return_value = True
        branch = api.get_current_branch(self.store)
        storable = self.create_storable(branch=branch, stock=1)
        sellable = storable.product.sellable
        # Run the wizard
        wizard = StockDecreaseWizard(self.store)
        step = wizard.get_current_step()
        step.reason.update('test')
        self.click(wizard.next_button)
        step = wizard.get_current_step()
        self.assertNotSensitive(step, ['delivery_button'])
        step.sellable_selected(sellable)
        step.quantity.update(1)
        self.click(step.add_sellable_button)
        self.assertSensitive(step, ['delivery_button'])

        delivery_sellable = sysparam.get_object(self.store, 'DELIVERY_SERVICE').sellable
        delivery = CreateDeliveryModel(price=delivery_sellable.price,
                                       recipient=wizard.model.person)

        module = 'stoqlib.gui.wizards.stockdecreasewizard.run_dialog'
        with mock.patch(module) as run_dialog:
            # Delivery set
            run_dialog.return_value = delivery
            self.click(step.delivery_button)
            self.assertEqual(step._delivery, delivery)
            self.assertTrue(isinstance(step._delivery_item, StockDecreaseItem))

            # Remove the delivery item
            run_dialog.return_value = delivery
            step.slave.klist.select(step.slave.klist[1])
            self.click(step.slave.delete_button)
            self.assertIsNone(step._delivery)
            self.assertIsNone(step._delivery_item)
Beispiel #4
0
    def setup_slaves(self):
        SellableItemStep.setup_slaves(self)
        self.hide_add_button()
        self.cost_label.set_label(_('Price:'))
        self.cost.set_editable(True)

        delivery = self._find_delivery()
        if delivery is not None:
            self._delivery_item = delivery.service_item
            self._delivery = CreateDeliveryModel(
                price=self._delivery_item.price,
                notes=self._delivery_item.notes,
                transporter=delivery.transporter,
                address=delivery.address,
                estimated_fix_date=self._delivery_item.estimated_fix_date)
        else:
            self._delivery = None
            self._delivery_item = None

        if isinstance(self.model, Sale):
            self.delivery_btn = self.slave.add_extra_button(
                label=_("Add delivery"))
            self.delivery_btn.set_sensitive(bool(len(self.slave.klist)))
        else:
            self.delivery_btn = None

        self.discount_btn = self.slave.add_extra_button(
            label=_("Apply discount"))
        self.discount_btn.set_sensitive(bool(len(self.slave.klist)))
        self.slave.klist.connect('has-rows', self._on_klist__has_rows)
        self.slave.klist.connect('selection-changed',
                                 self._on_klist__selection_changed)
Beispiel #5
0
    def setup_slaves(self):
        SellableItemStep.setup_slaves(self)
        self.hide_add_button()
        self.cost_label.set_label(_('Price:'))
        self.cost.set_editable(True)

        delivery = self._find_delivery()
        if delivery is not None:
            self._delivery_item = delivery.service_item
            self._delivery = CreateDeliveryModel.from_delivery(delivery)
        else:
            self._delivery = None
            self._delivery_item = None

        if isinstance(self.model, Sale):
            self.delivery_btn = self.slave.add_extra_button(label=_("Add delivery"))
            self.delivery_btn.set_sensitive(bool(len(self.slave.klist)))
        else:
            self.delivery_btn = None

        self.discount_btn = self.slave.add_extra_button(label=_("Apply discount"))
        self.discount_btn.set_sensitive(bool(len(self.slave.klist)))
        self.slave.klist.connect('has-rows', self._on_klist__has_rows)
        self.slave.klist.connect('selection-changed',
                                 self._on_klist__selection_changed)
Beispiel #6
0
    def test_wizard_with_delivery(self):
        branch = api.get_current_branch(self.store)
        storable = self.create_storable(branch=branch, stock=1)
        sellable = storable.product.sellable
        # Run the wizard
        wizard = StockDecreaseWizard(self.store)
        step = wizard.get_current_step()
        step.reason.update('test')
        self.click(wizard.next_button)
        step = wizard.get_current_step()
        self.assertNotSensitive(step, ['delivery_button'])
        step.sellable_selected(sellable)
        step.quantity.update(1)
        self.click(step.add_sellable_button)
        item = step.slave.klist[0]
        self.assertSensitive(step, ['delivery_button'])

        delivery_sellable = sysparam.get_object(self.store,
                                                'DELIVERY_SERVICE').sellable
        delivery = CreateDeliveryModel(price=delivery_sellable.price,
                                       recipient=wizard.model.person)

        module = 'stoqlib.gui.wizards.stockdecreasewizard.run_dialog'
        with mock.patch(module) as run_dialog:
            # Nothing done with the editor, no delivery returned
            run_dialog.return_value = None
            self.click(step.delivery_button)
            self.assertIsNone(step._delivery)
            self.assertIsNone(step._delivery_item)

            # Delivery set
            run_dialog.return_value = delivery
            self.click(step.delivery_button)
            self.assertEqual(step._delivery, delivery)
            self.assertTrue(isinstance(step._delivery_item, StockDecreaseItem))

            # Edit the delivery item
            run_dialog.return_value = delivery
            step.slave.klist.select(step.slave.klist[1])
            self.click(step.slave.edit_button)
            self.assertEqual(step._delivery, delivery)
            self.assertTrue(isinstance(step._delivery_item, StockDecreaseItem))

        # Finishing the wizard must create a Delivery object
        module = 'stoqlib.gui.wizards.stockdecreasewizard.yesno'
        with mock.patch(module) as yesno:
            with mock.patch.object(self.store, 'commit'):
                yesno.return_value = False
                item.deliver = True
                self.click(wizard.next_button)
                self.assertTrue(isinstance(item.delivery, Delivery))
Beispiel #7
0
    def test_create_delivery(self, run_dialog):
        delivery = CreateDeliveryModel(price=Decimal('150'))
        delivery.notes = u'notes about the delivery'
        delivery.client = self.create_client()
        delivery.transporter = self.create_transporter()
        delivery.address = self.create_address()
        run_dialog.return_value = delivery

        pos = self._get_pos_with_open_till()

        sale_item = self._add_product(pos, self.create_sellable())

        olist = pos.sale_items
        olist.select(olist[0])

        self.activate(pos.NewDelivery)
        self.assertEqual(run_dialog.call_count, 1)
        args, kwargs = run_dialog.call_args
        editor, store, delivery = args
        self.assertEqual(editor, CreateDeliveryEditor)
        self.assertTrue(store is not None)
        self.assertEqual(delivery, None)
        self.assertEqual(kwargs[u'items'], [sale_item])
Beispiel #8
0
    def test_create_delivery(self, run_dialog):
        delivery = CreateDeliveryModel(price=Decimal('150'))
        delivery.notes = u'notes about the delivery'
        delivery.client = self.create_client()
        delivery.transporter = self.create_transporter()
        delivery.address = self.create_address()
        run_dialog.return_value = delivery

        pos = self._get_pos_with_open_till()

        sale_item = self._add_product(pos, self.create_sellable())

        olist = pos.sale_items
        olist.select(olist[0])

        self.activate(pos.NewDelivery)
        self.assertEqual(run_dialog.call_count, 1)
        args, kwargs = run_dialog.call_args
        editor, store, delivery = args
        self.assertEqual(editor, CreateDeliveryEditor)
        self.assertTrue(store is not None)
        self.assertEqual(delivery, None)
        self.assertEqual(kwargs[u'items'], [sale_item])