示例#1
0
 def _get_components(self, product):
     for component in self.store.find(ProductComponent, product=product):
         yield TemporaryProductComponent(
             self.store,
             product=component.product,
             component=component.component,
             quantity=component.quantity,
             design_reference=component.design_reference,
             price=component.price)
示例#2
0
    def _run_product_component_dialog(self, product_component=None):
        update = True
        if product_component is None:
            update = False
            component = self.component_combo.get_selected_data()
            product_component = TemporaryProductComponent(
                self.store, product=self._product, component=component)
            # If we try to add a component which is already in tree,
            # just edit it
            for component in self.component_tree:
                if component.component == product_component.component:
                    update = True
                    product_component = component
                    break

        if not self._can_add_component(product_component):
            product_desc = self._product.sellable.get_description()
            component_desc = product_component.description
            info(
                _(u'You can not add this product as component, since '
                  '%s is composed by %s' % (component_desc, product_desc)))
            return

        toplevel = self.get_toplevel().get_toplevel()
        if self.model.product.is_package:
            model = run_dialog(ProductPackageComponentEditor, toplevel,
                               self.store, product_component)
        else:
            # We cant use savepoint here, since product_component
            # is not an ORM object.
            model = run_dialog(ProductComponentEditor, toplevel, self.store,
                               product_component)
        if not model:
            return

        if update:
            self.component_tree.update(model)
        else:
            self._add_to_component_tree(model)
        self._update_widgets()
    def test_create_package_product(self, run_dialog):
        wizard = ProductCreateWizard(self.store)
        type_step = wizard.get_current_step()
        type_step.package.set_active(True)
        self.click(wizard.next_button)

        # ProductEditor step
        editor_step = wizard.get_current_step()
        # Checking that the slave is attached
        self.assertEqual(hasattr(editor_step.slave, 'package_slave'), True)

        # Package slave
        package_slave = editor_step.slave.get_slave('Pack content')
        self.assertNotSensitive(package_slave,
                                ['add_button', 'remove_button', 'edit_button'])

        package_slave.component_combo.select_item_by_position(0)
        selected = package_slave.component_combo.get_selected()
        temp = TemporaryProductComponent(package_slave.store,
                                         product=package_slave._product,
                                         component=selected,
                                         price=10)
        # After select a component add button will be sensitive
        self.assertSensitive(package_slave, ['add_button'])
        # And the other remain not sensitive
        self.assertNotSensitive(package_slave,
                                ['remove_button', 'edit_button'])
        run_dialog.return_value = temp
        self.click(package_slave.add_button)

        args, kwargs = run_dialog.call_args
        self.assertEqual(args[0], ProductPackageComponentEditor)
        self.assertTrue(isinstance(args[2], StoqlibStore))
        self.assertTrue(isinstance(args[3], TemporaryProductComponent))
        self.assertTrue(hasattr(args[3], 'product'))
        self.assertTrue(hasattr(args[3], 'component'))
        self.assertTrue(hasattr(args[3], 'quantity'))
        self.assertTrue(hasattr(args[3], 'design_reference'))
        self.assertTrue(hasattr(args[3], 'price'))
示例#4
0
 def create_model(self, store):
     return TemporaryProductComponent(self.store, product=self._product)