Example #1
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)
Example #2
0
    def _create_production_order(self, store):
        desc = (_('Production for Sale order %s')
                   % self.sale.get_order_number_str())
        if self.sale.client:
            desc += ' (%s)' % self.sale.client.get_name()
        user = api.get_current_user(store)
        employee = user.person.employee
        order = ProductionOrder(branch=store.fetch(self.sale.branch),
                                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
            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=order,
                               product=material,
                               store=store)

        if materials:
            info(_('A new production was created for the missing composed '
                   'products'))
        else:
            store.remove(order)
Example #3
0
 def _create_model(self, store):
     branch = api.get_current_branch(store)
     return ProductionOrder(branch=branch,
                            store=store)
Example #4
0
 def create_production_order(self):
     from stoqlib.domain.production import ProductionOrder
     return ProductionOrder(branch=get_current_branch(self.store),
                            responsible=self.create_employee(),
                            description=u'production',
                            store=self.store)