Order and Inventory Management Direct for Avalara Custom Settings
OIM Direct for Avalara Plugins
The OIM Direct for Avalara Plugins custom setting determines the Apex classes to call when Order and Inventory Management communicates with Avalara AvaTax.
Field | Description |
---|---|
GetCompanyCode | Name of the Apex class to call to obtain the Avalara company when using Accounting. To use the sample class SCMAVACompanyCode, you must add a 25 character text field to the Company object in Accounting. |
SCMAVACompanyCode Class
global class SCMAVACompanyCode extends SCMAVA CompanyCodePlugin {
// If Accounting is being used, this is very simple. Add a text
// field (25 characters) to the Accounting Company object.
// This new field holds the Company Code that has been set up in Avalara.
// Then simply use the same logic to determine the Accounting company to determine the Avalara company.
global SCMAVACompanyCode() { }
global override string GetCompanyCode(Id recordId) {
Schema.SObjectType objType = getObjectTypeFromId(recordId);
if (objType == SCMC__Customer_Quotation__c.sObjectType) {
SCMC__Customer_Quotation__c quote = [select Id
, Company__r.Avalara_Company_Code__c
from SCMC__Customer_Quotation__c
where Id = :recordId];
return quote.Company__r.Avalara_Company_Code__c;;
} else if (objType == SCMC__Sales_Order__c.sObjectType) {
SCMC__Sales_Order__c so = [select Id
, Company__r.Avalara_Company_Code__c
from SCMC__Sales_Order__c
where Id = :recordId];
return so.Company__r.Avalara_Company_Code__c;
} else if (objType == SCMC__Invoicing__c.sObjectType) {
SCMC__Invoicing__c inv = [select Id
, Company__r.Avalara_Company_Code__c
from SCMC__Invoicing__c
where Id = :recordId];
return inv.Company__r.Avalara_Company_Code__c;
} else if (objType == SCMC__Credit_Invoice__c.sObjectType) {
SCMC__Credit_Invoice__c crInv = [select Id
, SCMC__Invoicing__r.Company__r.Avalara_Company_Code__c
from SCMC__Credit_Invoice__c
where Id = :recordId];
return crInv.SCMC__Invoicing__r.Company__r.Avalara_Company_Code__c;
} else if (objType == SCMC__Purchase_Order__c.sObjectType) {
SCMC__Purchase_Order__c po = [select Id
, Company__r.Avalara_Company_Code__c
from SCMC__Purchase_Order__c
where Id = :recordId];
return po.Company__r.Avalara_Company_Code__c;
} else if (objType == SCMC__AP_Voucher__c.sObjectType) {
SCMC__AP_Voucher__c voucher = [select Id
, SCMC__Purchase_Order__r.Company__r.Avalara_Company_Code__c
from SCMC__AP_Voucher__c
where Id = :recordId];
return voucher.SCMC__Purchase_Order__r.Company__r.Avalara_Company_Code__c;
} else if (objType == SCMC__AP_Voucher_Credit__c.sObjectType) {
SCMC__AP_Voucher_Credit__c voucherCr = [select Id
, SCMC__Purchase_Order__r.Company__r.Avalara_Company_Code__c
from SCMC__AP_Voucher_Credit__c
where Id = :recordId];
return voucherCr.SCMC__Purchase_Order__r.Company__r.Avalara_Company_Code__c;
}
// returning null will use the default company set up in Avalara
return null;
}
private Schema.SObjectType getObjectTypeFromId(Id recordId) {
Map<string,Schema.SObjectType> theMap = new Map<string,Schema.SObjectType>();
string recordIdPrefix = ((string)recordId).substring(0,3);
for (Schema.SObjectType so : Schema.getGlobalDescribe().values()) {
Schema.DescribeSObjectResult od = so.getDescribe();
if (od.getKeyPrefix() != null) {
theMap.put(od.getKeyPrefix(), od.getSobjectType());
}
}
return theMap.get(recordIdPrefix);
}
}
Avalara Nexus Regions
We recommend that you set up nexus regions in Avalara for each state for which tax is to be collected and ignore this custom setting.
Avalara Valid Countries
The Avalara Valid Countries custom setting contains a list of countries to be validated through the Avalara AvaTax service. When you validate an address, the country that you specify for that address must exist in this custom setting otherwise the address fails validation.