コード例 #1
0
    def _create_order(self):
        # Create production order
        order = self.create_production_order()
        order.identifier = 75423

        # Create product and components (1 of each)
        product = self.create_product(stock=0)
        product.sellable.description = u'Composed product'
        self.create_storable(product)

        component1 = self.create_product(stock=20, branch=order.branch)
        component1.sellable.description = u'Component 1'
        self.create_product_component(product=product, component=component1)
        component2 = self.create_product(stock=30, branch=order.branch)
        component2.sellable.description = u'Component 2'
        self.create_product_component(product=product, component=component2)

        # Add the products we want to produce:
        order.add_item(product.sellable, quantity=10)

        # And create the material we will need.
        # TODO: This should be in domain.
        ProductionMaterial(store=self.store,
                           order=order,
                           product=component1,
                           needed=10)
        ProductionMaterial(store=self.store,
                           order=order,
                           product=component2,
                           needed=10)

        return order
コード例 #2
0
 def material(self):
     if self._material is None:
         # At this point, the needed quantity have already been updated.
         assert self.needed > 0
         material = self._store.find(ProductionMaterial, order=self.order,
                                     product=self.product).one()
         if material is not None:
             self._material = material
             self._material.needed = self.needed
         else:
             self._material = ProductionMaterial(
                 needed=self.needed,
                 to_purchase=self.to_purchase,
                 to_make=self.to_make,
                 order=self.order,
                 product=self.product,
                 store=self._store)
     return self._material
コード例 #3
0
    def _create_production_order(self, store):
        desc = _(u'Production for Sale order %s') % self.order.identifier
        if self.order.client:
            desc += ' (%s)' % self.order.client.get_name()
        user = api.get_current_user(store)
        employee = user.person.employee
        prod_order = ProductionOrder(branch=store.fetch(self.order.branch),
                                     station=api.get_current_station(store),
                                     status=ProductionOrder.ORDER_WAITING,
                                     responsible=employee,
                                     description=desc,
                                     store=store)

        materials = {}
        for item in self.missing:
            product = store.fetch(item.storable.product)
            components = list(product.get_components())
            if not components:
                continue
            qty = item.ordered - item.stock
            prod_order.add_item(product.sellable, qty)

            # Merge possible duplicate components from different products
            for component in components:
                materials.setdefault(component.component, 0)
                materials[component.component] += component.quantity * qty

        for material, needed in materials.items():
            ProductionMaterial(needed=needed,
                               order=prod_order,
                               product=material,
                               store=store)

        if materials:
            info(
                _('A new production was created for the missing composed '
                  'products'))
        else:
            store.remove(prod_order)
コード例 #4
0
    def create_production_item(self, quantity=1, order=None):
        from stoqlib.domain.product import ProductComponent, Storable
        from stoqlib.domain.production import (ProductionItem,
                                               ProductionMaterial)
        product = self.create_product(10)
        Storable(product=product, store=self.store)
        component = self.create_product(5)
        Storable(product=component, store=self.store)
        ProductComponent(product=product,
                         component=component,
                         store=self.store)

        if not order:
            order = self.create_production_order()
        component = list(product.get_components())[0]
        ProductionMaterial(product=component.component,
                           order=order,
                           needed=quantity,
                           store=self.store)

        return ProductionItem(product=product,
                              order=order,
                              quantity=quantity,
                              store=self.store)