def add_mandatory_product(self, code, quantity):
        # The function needs to check to see if it is already satisfied before
        # calling this. This function will always reclaim or create a new line
        # with the specified quantity. this is because add_mandatory_items
        # gets called multiple times, but does NOT unclaim everything like
        # sync_all_children does, because it may be that the mandatory items
        # themselves require more mandatory items. (Ex: for some reason,
        # businesses in california MUST have a smoke detector.)

        mp = self.reclaim_line(code=code, line_type='MANDATORY')
        if not mp:
            mp = InvoiceLine(agreement=self.agreement)
            product = self.products.get(code)
            if not product:
                self.errors.append('Could not add mandatory product %r' % code)
                return
            price = self.prices.get(code)
            if not price:
                self.errors.append(
                    'Mandatory product %r has no price.  Campaign=%r' %
                    (code, self.agreement.campaign_id))

            mp.update_mandatory(quantity=quantity,
                                product=product,
                                price=price,
                                pricedate=self.agreement.pricedate)

        mp.quantity = quantity
        mp.save()
        self.final_lines.append(mp)
    def add_mandatory_product(self, code, quantity):
        # The function needs to check to see if it is already satisfied before
        # calling this. This function will always reclaim or create a new line
        # with the specified quantity. this is because add_mandatory_items
        # gets called multiple times, but does NOT unclaim everything like
        # sync_all_children does, because it may be that the mandatory items
        # themselves require more mandatory items. (Ex: for some reason,
        # businesses in california MUST have a smoke detector.)


        mp = self.reclaim_line(code=code, line_type='MANDATORY')
        if not mp:
            mp = InvoiceLine(agreement=self.agreement)
            product = self.products.get(code)
            if not product:
                self.errors.append('Could not add mandatory product %r' % code)
                return
            price = self.prices.get(code)
            if not price:
                self.errors.append('Mandatory product %r has no price.  Campaign=%r' % (code, self.agreement.campaign_id))

            mp.update_mandatory(quantity=quantity, product=product, price=price, pricedate=self.agreement.pricedate)

        mp.quantity = quantity
        mp.save()
        self.final_lines.append(mp)