private void checkForTaxCodesInCustomFields(
      final Invoice invoice,
      final Collection<PluginProperty> properties,
      final TenantContext context) {
    final List<CustomField> customFields =
        killbillAPI
            .getCustomFieldUserApi()
            .getCustomFieldsForAccountType(
                invoice.getAccountId(), ObjectType.INVOICE_ITEM, context);
    if (customFields.isEmpty()) {
      return;
    }

    final Collection<UUID> invoiceItemIds = new HashSet<UUID>();
    for (final InvoiceItem invoiceItem : invoice.getInvoiceItems()) {
      invoiceItemIds.add(invoiceItem.getId());
    }

    final Iterable<CustomField> taxCodeCustomFieldsForInvoiceItems =
        Iterables.<CustomField>filter(
            customFields,
            new Predicate<CustomField>() {
              @Override
              public boolean apply(final CustomField customField) {
                return AvaTaxTaxCalculator.TAX_CODE.equals(customField.getFieldName())
                    && invoiceItemIds.contains(customField.getObjectId());
              }
            });
    for (final CustomField customField : taxCodeCustomFieldsForInvoiceItems) {
      final UUID invoiceItemId = customField.getObjectId();
      final String taxCode = customField.getFieldValue();
      addTaxCodeToInvoiceItem(invoiceItemId, taxCode, properties);
    }
  }
  private void checkForTaxExemption(
      final Invoice invoice,
      final Collection<PluginProperty> properties,
      final TenantContext context) {
    // Overridden by plugin properties?
    if (PluginProperties.findPluginPropertyValue(
            AvaTaxTaxCalculator.CUSTOMER_USAGE_TYPE, properties)
        != null) {
      return;
    }

    final List<CustomField> customFields =
        killbillAPI
            .getCustomFieldUserApi()
            .getCustomFieldsForObject(invoice.getAccountId(), ObjectType.ACCOUNT, context);
    final CustomField customField =
        Iterables.<CustomField>tryFind(
                customFields,
                new Predicate<CustomField>() {
                  @Override
                  public boolean apply(final CustomField customField) {
                    return AvaTaxTaxCalculator.CUSTOMER_USAGE_TYPE.equals(
                        customField.getFieldName());
                  }
                })
            .orNull();

    if (customField != null) {
      properties.add(
          new PluginProperty(
              AvaTaxTaxCalculator.CUSTOMER_USAGE_TYPE, customField.getFieldValue(), false));
    }
  }
Exemplo n.º 3
0
 private InvoiceItem createTaxInvoiceItem(final Invoice invoice) {
   return new TaxInvoiceItem(
       invoice.getId(),
       invoice.getAccountId(),
       null,
       "Tax Item",
       clock.getUTCNow().toLocalDate(),
       BigDecimal.ONE,
       invoice.getCurrency());
 }