public async Task TestCreateUpdateDeleteInvoice() { var newInvoice = new NewOutgoingInvoice { CustomerCode = 1522391, Status = OutgoingInvoiceStatus.Approved }; newInvoice.OutgoingInvoiceLines.Add(new OutgoingInvoiceLine { Description = "Created by automated test" }); var createdInvoice = await Client.CreateInvoice(newInvoice); createdInvoice.Status.Should().Be(newInvoice.Status); createdInvoice.OutgoingInvoiceLines.Should().HaveCount(1); createdInvoice.OutgoingInvoiceLines[0].Description.Should().Be(newInvoice.OutgoingInvoiceLines[0].Description); createdInvoice.Status = OutgoingInvoiceStatus.Draft; var updatedInvoice = await Client.UpdateInvoice(createdInvoice); updatedInvoice.Id.Should().Be(createdInvoice.Id); updatedInvoice.Status.Should().Be(createdInvoice.Status); await Client.DeleteInvoice(createdInvoice.Id); await Assert.ThrowsAsync <ApplicationException>(async() => await Client.GetInvoice(createdInvoice.Id)); }
public async Task <OutgoingInvoice> CreateInvoice(NewOutgoingInvoice newInvoice) { var createResponse = await AuthorizedPost("OutgoingInvoice", newInvoice); var createdInvoice = await DeserializeScalarResponse <OutgoingInvoice>(createResponse, "outgoing invoice"); return(createdInvoice); }
public async Task CopyDeliveryToPoweroffice( DeliveryDto webcrmDelivery, List <QuotationLineDto> webcrmDeliveryLines) { Guid?powerofficeDeliveryId = webcrmDelivery.GetPowerofficeDeliveryId(Configuration.DeliveryIdFieldName); if (powerofficeDeliveryId == null) { long?powerofficeCustomerCode = await GetPowerofficeCustomerCode(webcrmDelivery); if (!powerofficeCustomerCode.HasValue) { Logger.LogInformation($"Not copying webCRM delivery with ID {webcrmDelivery.DeliveryId} to PowerOffice because the corresponding PowerOffice organisation could not be found."); return; } Logger.LogTrace("Copying delivery to PowerOffice, creating a new one."); var newPowerofficeDelivery = new NewOutgoingInvoice(webcrmDelivery, webcrmDeliveryLines, powerofficeCustomerCode.Value, Configuration.ProductIdFieldName); var createdPowerofficeDelivery = await PowerofficeClient.CreateInvoice(newPowerofficeDelivery); webcrmDelivery.SetPowerofficeDeliveryId(Configuration.DeliveryIdFieldName, createdPowerofficeDelivery.Id); await WebcrmClient.UpdateDelivery(webcrmDelivery); if (createdPowerofficeDelivery.OutgoingInvoiceLines.Count != webcrmDeliveryLines.Count) { throw new ApplicationException($"Sanity check failed: Expected the same number of lines in newly created PowerOffice delivery. Lines in webCRM delivery: {webcrmDeliveryLines.Count}. Lines in PowerOffice delivery: {createdPowerofficeDelivery.OutgoingInvoiceLines.Count}."); } } else { var matchingPowerofficeDelivery = await PowerofficeClient.GetInvoice(powerofficeDeliveryId.Value); if (matchingPowerofficeDelivery == null) { Logger.LogWarning($"Could not find PowerOffice delivery (invoice) with id {powerofficeDeliveryId.Value}. Not copying the delivery to PowerOffice."); return; } // Not comparing the two deliveries, since we're only synchronising deliveries one way. long?powerofficeCustomerCode = await GetPowerofficeCustomerCode(webcrmDelivery); if (!powerofficeCustomerCode.HasValue) { Logger.LogInformation($"Not copying webCRM delivery with ID {webcrmDelivery.DeliveryId} to PowerOffice because the corresponding PowerOffice organisation could not be found."); return; } Logger.LogTrace("Copying delivery to PowerOffice, updating an existing one."); matchingPowerofficeDelivery.UpdateIncludingLines(webcrmDelivery, webcrmDeliveryLines, powerofficeCustomerCode.Value, Configuration.ProductCodeFieldName); await PowerofficeClient.UpdateInvoice(matchingPowerofficeDelivery); } }