Delete Invoice from Xero

118 views Asked by At

I'm trying to delete an invoice from Xero by updating its status to "DELETED". Following the xeroizer github page I have tried the following:

xero = XeroApp.find_by(business_id: 270);
invoice = xero.find_invoice_by_ref(372).first
delete_invoice = xero.xero_client.Invoice.build(id: invoice.id, status: 'DELETED')
delete_invoice.save #=> false
delete_invoice.status #=> "AUTHORISED"

Unfortunately this doesn't update the invoice status. I thought that maybe removing the corresponding payment may help but it didn't. Incidentally I used a similar approach for removing the payment as above which did work.


Response to delete_invoice.save is:

XeroGateway Request: GET /api.xro/2.0/Invoices/09b354ba-c659-4aac-b353-7d56cb52c2d6?unitdp=4
XeroGateway Response (200)
/api.xro/2.0/Invoices/09b354ba-c659-4aac-b353-7d56cb52c2d6?unitdp=4
== Response Body

<Response xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-
instance">
  <Id>3033fc56-2eed-446c-a16b-1c0a3678f6cf</Id>
  <Status>OK</Status>
  <ProviderName>My-App</ProviderName>
  <DateTimeUTC>2022-02-24T13:40:46.7218944Z</DateTimeUTC>
  <Invoices>
    <Invoice>
      <Contact>
        <ContactID>0bb81c84-22a0-40fc-a12b-322646752710</ContactID>
        <ContactStatus>ACTIVE</ContactStatus>
        <Name>Sagar Pandya</Name>
        <Addresses>
          <Address>
            <AddressType>STREET</AddressType>
          </Address>
          <Address>
            <AddressType>POBOX</AddressType>
            <AddressLine1>123 High Road</AddressLine1>
            <City>London</City>
            <PostalCode>SW1 8RE</PostalCode>
            <Country>United Kingdom</Country>
          </Address>
        </Addresses>
        <Phones>
          <Phone>
            <PhoneType>DEFAULT</PhoneType>
            <PhoneNumber>07123456789</PhoneNumber>
          </Phone>
          <Phone>
            <PhoneType>DDI</PhoneType>
          </Phone>
          <Phone>
            <PhoneType>FAX</PhoneType>
          </Phone>
          <Phone>
            <PhoneType>MOBILE</PhoneType>
          </Phone>
        </Phones>
        <UpdatedDateUTC>2022-02-08T20:01:08.327</UpdatedDateUTC>
        <IsSupplier>false</IsSupplier>
        <IsCustomer>true</IsCustomer>
      </Contact>
      <Date>2022-02-24T00:00:00</Date>
      <DueDate>2022-02-24T00:00:00</DueDate>
      <BrandingThemeID>5d4dd402-c851-497e-aae1-9ff265c0d15a</BrandingThemeID>
      <Status>AUTHORISED</Status>
      <LineAmountTypes>Exclusive</LineAmountTypes>
      <LineItems>
        <LineItem>
          <ItemCode>FOOTYT</ItemCode>
          <Description>Football T-Shirt</Description>
          <UnitAmount>100.0000</UnitAmount>
          <TaxType>NONE</TaxType>
          <TaxAmount>0.00</TaxAmount>
          <LineAmount>100.00</LineAmount>
          <AccountCode>200</AccountCode>
          <Item>
            <ItemID>0ad76998-051d-4031-9f97-fba6b9bb255e</ItemID>
            <Code>FOOTYT</Code>
          </Item>
          <Quantity>1.0000</Quantity>
          <LineItemID>497fc08c-3571-49cb-bcd7-6a28533f9d34</LineItemID>
        </LineItem>
      </LineItems>
      <SubTotal>100.00</SubTotal>
      <TotalTax>0.00</TotalTax>
      <Total>100.00</Total>
      <UpdatedDateUTC>2022-02-24T12:26:13.317</UpdatedDateUTC>
      <CurrencyCode>GBP</CurrencyCode>
      <Type>ACCREC</Type>
      <InvoiceID>09b354ba-c659-4aac-b353-7d56cb52c2d6</InvoiceID>
      <InvoiceNumber>INV-0073</InvoiceNumber>
      <Reference>372</Reference>
      <AmountDue>100.00</AmountDue>
      <AmountPaid>0.00</AmountPaid>
      <SentToContact>false</SentToContact>
      <CurrencyRate>1.0000000000</CurrencyRate>
      <HasAttachments>false</HasAttachments>
      <HasErrors>false</HasErrors>
    </Invoice>
  </Invoices>
</Response>
== End Response Body
=> false

1

There are 1 answers

0
Sagar Pandya On

Use the methods outlined in the api here:

https://github.com/waynerobinson/xeroizer/blob/master/lib/xeroizer/models/invoice.rb

For this question: After retrieving the invoice use invoice.void!.