Imports uninvoiced items (time entries, expenses, flat fee tasks)
 that belong to the same client that this invoice was created for.

 Either raises a Cashboard error (errors.rb) or returns a collection
 of Cashboard::InvoiceLineItem objects.
548690
def import_uninvoiced_items(project_ids={}, start_date=nil, end_date=nil)
      xml_options = get_import_xml_options(project_ids, start_date, end_date)
      
      options = self.class.merge_options()
      options.merge!({:body => xml_options})
      response = self.class.put(self.links[:import_uninvoiced_items], options)
      
      self.class.check_status_code(response)
      
      collection = response.parsed_response[Cashboard::InvoiceLineItem.resource_name.singularize]      
      collection.map do |h| 
        Cashboard::InvoiceLineItem.new(h)
      end
    end
317680
def get_unpaid_items(self, acc: Account) -> list:
        
        unpaid_items = []
        for item, bal in self.get_item_balances(acc):
            assert isinstance(item, AccountEntry)
            if self.type == INVOICE_DEFAULT:
                if bal > Decimal(0):
                    unpaid_items.append((item.type.payback_priority, item, bal))
            elif self.type == INVOICE_CREDIT_NOTE:
                if bal < Decimal(0):
                    unpaid_items.append((item.type.payback_priority, item, bal))
            else:
                raise Exception('jacc.models.Invoice.get_unpaid_items() unimplemented for invoice type {}'.format(self.type))
        return [i[1:] for i in sorted(unpaid_items, key=lambda x: x[0])]
188560
def process_import_job(list, emails, report_email = nil, postback_url = nil, options = {})
      data = options
      data['list'] = list
      data['emails'] = Array(emails).join(',')
      process_job(:import, data, report_email, postback_url)
    end
1186416
def dispatch(self,request,*args,**kwargs):
        '''
        
        '''
        paymentSession = request.session.get(INVOICE_VALIDATION_STR, {})
        self.invoiceID = paymentSession.get('invoiceID')
        self.amount = paymentSession.get('amount',0)
        self.success_url = paymentSession.get('success_url',reverse('registration'))

        # Check that Invoice matching passed ID exists
        try:
            i = Invoice.objects.get(id=self.invoiceID)
        except ObjectDoesNotExist:
            return HttpResponseBadRequest(_('Invalid invoice information passed.'))

        if i.unpaid or i.amountPaid != self.amount:
            return HttpResponseBadRequest(_('Passed invoice is not paid.'))

        return super(GiftCertificateCustomizeView,self).dispatch(request,*args,**kwargs)
438017
def filter_spent_outputs(self, outputs):
        
        links = [o.to_dict() for o in outputs]
        txs = list(query.get_spending_transactions(self.connection, links))
        spends = {TransactionLink.from_dict(input_['fulfills'])
                  for tx in txs
                  for input_ in tx['inputs']}
        return [ff for ff in outputs if ff not in spends]
1225307
def read_items(client, items)
      return [] if !items
      items.map do |item_class,items_of_class|
        items_of_class = [items_of_class] if !items_of_class.is_a?(Array)
        items_of_class.map do |item|
          Item.new(client, item_class, item)
        end
      end.flatten
    end
884625
def rsub(self, items):
        
        ignore = self._seen
        seen = set()
        add = seen.add
        items = [i for i in items
                 if i not in ignore and i not in seen and not add(i)]
        return self._fromargs(seen, items)
170264
def valid?
      @errors = []

      if !INVOICE_TYPE[invoice_type]
        @errors << ['invoice_type', "must be one of #{INVOICE_TYPE.keys.join('/')}"]
      end

      if !invoice_id.nil? && invoice_id !~ GUID_REGEX
        @errors << ['invoice_id', 'must be blank or a valid Xero GUID']
      end

      if invoice_status && !INVOICE_STATUS[invoice_status]
        @errors << ['invoice_status', "must be one of #{INVOICE_STATUS.keys.join('/')}"]
      end

      if line_amount_types && !LINE_AMOUNT_TYPES[line_amount_types]
        @errors << ['line_amount_types', "must be one of #{LINE_AMOUNT_TYPES.keys.join('/')}"]
      end

      unless date
        @errors << ['invoice_date', "can't be blank"]
      end

      # Make sure contact is valid.
      unless @contact && @contact.valid?
        @errors << ['contact', 'is invalid']
      end

      # Make sure all line_items are valid.
      unless line_items.all? { | line_item | line_item.valid? }
        @errors << ['line_items', "at least one line item invalid"]
      end

      @errors.size == 0
    end
500337
def line_items(self):
        """"""
        if self._line_items is None:
            self._line_items = self.contributor.line_items.filter(
                payment_date__range=(self.start, self.end)
            )
        return self._line_items
894405
def get_import_lines(self):
        
        if self.imports:
            return ["from %s import %s" % (value, key) for key, value in self.imports.items()]
        else:
            return []
907695
def _ItemsToUrns(self, items):
    """"""
    for item in items:
      try:
        yield flow_export.CollectionItemToAff4Path(item, self.client_id)
      except flow_export.ItemNotExportableError:
        pass
137093
def line_items
      if line_items_downloaded?
        @line_items

      # There is an credit_note_is so we can assume this record was loaded from Xero.
      # attempt to download the line_item records.
      elsif credit_note_id =~ GUID_REGEX
        raise NoGatewayError unless @gateway

        response = @gateway.get_credit_note(credit_note_id)
        raise CreditNoteNotFoundError, "CreditNote with ID #{credit_note_id} not found in Xero." unless response.success? && response.credit_note.is_a?(XeroGateway::CreditNote)

        @line_items = response.credit_note.line_items
        @line_items_downloaded = true

        @line_items

      # Otherwise, this is a new credit_note, so return the line_items reference.
      else
        @line_items
      end
    end
762521
public void addItem(final InvoiceItem invoiceItem) {
        Preconditions.checkState(!isBuilt, "Tree already built, unable to add new invoiceItem=%s", invoiceItem);

        switch (invoiceItem.getInvoiceItemType()) {
            case RECURRING:
                if (invoiceItem.getAmount().compareTo(BigDecimal.ZERO) == 0) {
                    // Nothing to repair -- https://github.com/killbill/killbill/issues/783
                    existingIgnoredItems.add(invoiceItem);
                } else {
                    root.addExistingItem(new ItemsNodeInterval(root, new Item(invoiceItem, targetInvoiceId, ItemAction.ADD)));
                }
                break;

            case REPAIR_ADJ:
                root.addExistingItem(new ItemsNodeInterval(root, new Item(invoiceItem, targetInvoiceId, ItemAction.CANCEL)));
                break;

            case FIXED:
                existingIgnoredItems.add(invoiceItem);
                break;

            case ITEM_ADJ:
                pendingItemAdj.add(invoiceItem);
                break;

            default:
                break;
        }
    }
1265231
def value(self, item=0, default=None):
        
        return [record.value(item, default) for record in self.records()]
610614
def initialize_properties_with_values_from_owner(invoice)
      if owner.is_a?(Debtor)
        invoice.debtor = owner

        invoice.debtor_name         ||= owner.name
        invoice.debtor_address      ||= owner.address
        invoice.debtor_postal_code  ||= owner.postal_code
        invoice.debtor_city         ||= owner.city

        invoice.term_of_payment_handle  ||= owner.term_of_payment_handle
        invoice.layout_handle           ||= owner.layout_handle
        invoice.currency_handle         ||= owner.currency_handle
      end
    end
273520
def import_item(name):
    
    package = '.'.join(name.split('.')[0:-1])
    obj = name.split('.')[-1]

    if package:
        module = __import__(package,fromlist=[obj])
        return module.__dict__[obj]
    else:
        return __import__(obj)
345423
def create_from_item(cls, amount, item_description, **kwargs):
        '''
        
        '''
        submissionUser = kwargs.pop('submissionUser', None)
        collectedByUser = kwargs.pop('collectedByUser', None)
        calculate_taxes = kwargs.pop('calculate_taxes', False)
        grossTotal = kwargs.pop('grossTotal',None)

        new_invoice = cls(
            grossTotal=grossTotal or amount,
            total=amount,
            submissionUser=submissionUser,
            collectedByUser=collectedByUser,
            buyerPaysSalesTax=getConstant('registration__buyerPaysSalesTax'),
            data=kwargs,
        )

        if calculate_taxes:
            new_invoice.calculateTaxes()

        new_invoice.save()

        InvoiceItem.objects.create(
            invoice=new_invoice,
            grossTotal=grossTotal or amount,
            total=amount,
            taxes=new_invoice.taxes,
            description=item_description,
        )
        return new_invoice