Browse Source

Fixing errors with customer post

Kenric Nugteren 1 năm trước cách đây
mục cha
commit
0932301ff0

+ 4 - 1
prs.shared/Posters/MYOB/CustomerMYOBPoster.cs

@@ -120,6 +120,7 @@ public class CustomerMYOBPoster : IMYOBPoster<Customer, CustomerMYOBPosterSettin
         // Notes = 
         // PhotoURI =
         // RowVersion = 
+        myobCustomer.SellingDetails ??= new();
         myobCustomer.SellingDetails.SaleLayout = InvoiceLayoutType.NoDefault;
         // myobCustomer.SellingDetails.PrintedFOrm = 
         myobCustomer.SellingDetails.InvoiceDelivery = DocumentAction.PrintAndEmail;
@@ -144,7 +145,9 @@ public class CustomerMYOBPoster : IMYOBPoster<Customer, CustomerMYOBPosterSettin
                 {
                     return Result.Error(new Exception($"Failed to find TaxCode in MYOB with code {settings.DefaultTaxCode}"));
                 }
+                myobCustomer.SellingDetails.TaxCode ??= new();
                 myobCustomer.SellingDetails.TaxCode.UID = taxID;
+                myobCustomer.SellingDetails.FreightTaxCode ??= new();
                 myobCustomer.SellingDetails.FreightTaxCode.UID = taxID;
             }
             else
@@ -249,7 +252,7 @@ public class CustomerMYOBPoster : IMYOBPoster<Customer, CustomerMYOBPosterSettin
             {
                 try
                 {
-                    var result = service.UpdateEx(ConnectionData.CompanyFile, myobCustomer, ConnectionData.CompanyFileCredentials);
+                    var result = service.Save(ConnectionData, myobCustomer);
                     customer.PostedReference = result.UID.ToString();
                     results.AddSuccess(customer);
                 }

+ 15 - 0
prs.shared/Posters/MYOB/PRSMYOBPosterUtils.cs

@@ -78,6 +78,21 @@ public static class PRSMYOBPosterUtils
         }
     }
 
+    public static T Save<T>(
+        this MutableService<T> service, MYOBConnectionData data,
+        T entity)
+        where T : MYOBBaseEntity
+    {
+        if(entity.UID == Guid.Empty)
+        {
+            return service.InsertEx(data.CompanyFile, entity, data.CompanyFileCredentials);
+        }
+        else
+        {
+            return service.UpdateEx(data.CompanyFile, entity, data.CompanyFileCredentials);
+        }
+    }
+
     public static GetResult<T> Get<T>(this MutableService<T> service, MYOBConnectionData data, Guid id)
         where T : MYOBBaseEntity
     {