示例#1
0
文件: order.py 项目: Betriebsrat/ecm
 def create_jobs(self, ignore_fixed_prices=False, calculate_surcharge=False):
     """
     Create all jobs needed to complete this order.
     Calculating costs for all the order's rows.
     """
     prices = {}
     for sp in Supply.objects.all():
         prices[sp.typeID] = sp.price
     all_missing_prices = set([])
     
     self.quote = 0.0
     
     for row in self.rows.all():
         cost, miss_prices = row.create_jobs(prices=prices)
         all_missing_prices.update(miss_prices)
         
         if ignore_fixed_prices or row.catalog_entry.fixed_price is None:
             if calculate_surcharge:
                 surcharge = PricingPolicy.resolve_surcharge(row.catalog_entry, self.originator, row.cost)
             else:
                 surcharge = 0.0
         else:
             surcharge = row.catalog_entry.fixed_price * row.quantity
             cost = 0.0
         
         row.surcharge = surcharge
         row.cost = cost
         row.save()
         self.quote += cost + surcharge
         
     self.save()
     
     return all_missing_prices
示例#2
0
文件: order.py 项目: vanderheyde/ecm
    def modify(self, entries):
        """
        Modification of the order.
        An order can only be modified if its state is DRAFT or PENDING.

        entries must be a list of tuples such as :
        [(CatalogEntry_A, qty_A), (CatalogEntry_B, qty_B), (CatalogEntry_C, qty_C)]
        """
        if self.rows.all() or self.logs.all():
            comment = "Modified by originator."
        else:
            comment = "Created."
        self.apply_transition(Order.modify, Order.DRAFT, self.originator,
                              comment)
        self.rows.all().delete()

        self.quote = 0.0
        missing_price = False
        for entry, quantity in entries:
            cost = 0.0
            surcharge = 0.0
            if entry.production_cost is None and entry.fixed_price is None:
                missing_price = True
            else:
                if entry.fixed_price is not None:
                    surcharge = entry.fixed_price
                else:
                    cost = entry.production_cost
                    surcharge = PricingPolicy.resolve_surcharge(
                        entry, self.originator, cost)

            self.quote += quantity * (cost + surcharge)
            self.rows.create(catalog_entry=entry,
                             quantity=quantity,
                             cost=cost,
                             surcharge=surcharge)
        if missing_price:
            self.quote = 0.0
        self.save()
示例#3
0
文件: order.py 项目: Betriebsrat/ecm
    def modify(self, entries):
        """
        Modification of the order.
        An order can only be modified if its state is DRAFT or PENDING.

        entries must be a list of tuples such as :
        [(CatalogEntry_A, qty_A), (CatalogEntry_B, qty_B), (CatalogEntry_C, qty_C)]
        """
        if self.rows.all() or self.logs.all():
            comment = "Modified by originator."
        else:
            comment = "Created."
        self.apply_transition(Order.modify, Order.DRAFT, self.originator, comment)
        self.rows.all().delete()

        self.quote = 0.0
        missing_price = False
        for entry, quantity in entries:
            cost = 0.0
            surcharge = 0.0
            if entry.production_cost is None and entry.fixed_price is None:
                missing_price = True
            else:
                if entry.fixed_price is not None:
                    surcharge = entry.fixed_price
                else:
                    cost = entry.production_cost
                    surcharge = PricingPolicy.resolve_surcharge(entry, self.originator, cost)
            
            self.quote += quantity * (cost + surcharge)
            self.rows.create(catalog_entry=entry, 
                             quantity=quantity, 
                             cost=cost, 
                             surcharge=surcharge)
        if missing_price:
            self.quote = 0.0
        self.save()
示例#4
0
文件: order.py 项目: vanderheyde/ecm
    def create_jobs(self,
                    ignore_fixed_prices=False,
                    calculate_surcharge=False):
        """
        Create all jobs needed to complete this order.
        Calculating costs for all the order's rows.
        """
        prices = {}
        for sp in Supply.objects.all():
            prices[sp.typeID] = sp.price
        all_missing_prices = set([])

        self.quote = 0.0

        for row in self.rows.all():
            cost, miss_prices = row.create_jobs(prices=prices)
            all_missing_prices.update(miss_prices)

            if ignore_fixed_prices or row.catalog_entry.fixed_price is None:
                if calculate_surcharge:
                    surcharge = PricingPolicy.resolve_surcharge(
                        row.catalog_entry, self.originator, row.cost)
                else:
                    surcharge = 0.0
            else:
                surcharge = row.catalog_entry.fixed_price * row.quantity
                cost = 0.0

            row.surcharge = surcharge
            row.cost = cost
            row.save()
            self.quote += cost + surcharge

        self.save()

        return all_missing_prices