|
@@ -156,8 +156,8 @@ public class CustomerMYOBPoster : IMYOBPoster<Customer, CustomerMYOBPosterSettin
|
|
|
myobCustomer.IsActive = customer.CustomerStatus.ID == Guid.Empty || customer.CustomerStatus.Active;
|
|
|
myobCustomer.Addresses =
|
|
|
[
|
|
|
- ContactMYOBUtils.ConvertAddress(customer.Delivery, 1, customer.DefaultContact),
|
|
|
- ContactMYOBUtils.ConvertAddress(customer.Postal, 2, customer.DefaultContact)
|
|
|
+ ContactMYOBUtils.ConvertAddress(customer.Postal, 2, customer.DefaultContact),
|
|
|
+ ContactMYOBUtils.ConvertAddress(customer.Delivery, 1, customer.DefaultContact)
|
|
|
];
|
|
|
// Notes =
|
|
|
// PhotoURI =
|
|
@@ -185,7 +185,7 @@ public class CustomerMYOBPoster : IMYOBPoster<Customer, CustomerMYOBPosterSettin
|
|
|
{
|
|
|
if (taxID == Guid.Empty)
|
|
|
{
|
|
|
- return Result.Error(new Exception($"Failed to find TaxCode in MYOB with code {settings.DefaultTaxCode}"));
|
|
|
+ return Result.Error(new Exception($"Failed to find TaxCode in MYOB with code '{settings.DefaultTaxCode}'"));
|
|
|
}
|
|
|
myobCustomer.SellingDetails.TaxCode ??= new();
|
|
|
myobCustomer.SellingDetails.TaxCode.UID = taxID;
|
|
@@ -194,8 +194,8 @@ public class CustomerMYOBPoster : IMYOBPoster<Customer, CustomerMYOBPosterSettin
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- CoreUtils.LogException("", error, $"Failed to find TaxCode in MYOB with code {settings.DefaultTaxCode}");
|
|
|
- return Result.Error(new Exception($"Failed to find TaxCode in MYOB with code {settings.DefaultTaxCode}: {error.Message}", error));
|
|
|
+ CoreUtils.LogException("", error, $"Failed to find TaxCode in MYOB with code '{settings.DefaultTaxCode}'");
|
|
|
+ return Result.Error(new Exception($"Failed to find TaxCode in MYOB with code '{settings.DefaultTaxCode}': {error.Message}", error));
|
|
|
}
|
|
|
}
|
|
|
return Result.Ok();
|
|
@@ -239,6 +239,10 @@ public class CustomerMYOBPoster : IMYOBPoster<Customer, CustomerMYOBPosterSettin
|
|
|
customer.PostedReference = result.UID.ToString();
|
|
|
return Result.Ok(result.UID);
|
|
|
}
|
|
|
+ catch(ApiCommunicationException e)
|
|
|
+ {
|
|
|
+ return Result.Error(new Exception(PRSMYOBPosterUtils.FormatApiException(e), e));
|
|
|
+ }
|
|
|
catch (Exception e)
|
|
|
{
|
|
|
CoreUtils.LogException("", e, $"Error while posting customer {customer.ID}");
|
|
@@ -286,8 +290,25 @@ public class CustomerMYOBPoster : IMYOBPoster<Customer, CustomerMYOBPosterSettin
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- myobCustomer = new MYOBCustomer();
|
|
|
- isNew = true;
|
|
|
+ if(service.Query(ConnectionData, new Filter<MYOBCustomer>(x => x.DisplayID).IsEqualTo(customer.Code)).Get(out var myobCustomers, out error))
|
|
|
+ {
|
|
|
+ if(myobCustomers.Items.Length > 0)
|
|
|
+ {
|
|
|
+ myobCustomer = myobCustomers.Items[0];
|
|
|
+ isNew = false;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ myobCustomer = new MYOBCustomer();
|
|
|
+ isNew = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ CoreUtils.LogException("", error);
|
|
|
+ results.AddFailed(customer, error.Message);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
if(UpdateCustomer(ConnectionData, Settings, customer, myobCustomer, isNew).Get(out error))
|
|
@@ -298,6 +319,10 @@ public class CustomerMYOBPoster : IMYOBPoster<Customer, CustomerMYOBPosterSettin
|
|
|
customer.PostedReference = result.UID.ToString();
|
|
|
results.AddSuccess(customer);
|
|
|
}
|
|
|
+ catch(ApiCommunicationException e)
|
|
|
+ {
|
|
|
+ results.AddFailed(customer, PRSMYOBPosterUtils.FormatApiException(e));
|
|
|
+ }
|
|
|
catch(Exception e)
|
|
|
{
|
|
|
CoreUtils.LogException("", e, $"Error while posting customer {customer.ID}");
|