Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UpdateRepeatingInvoice failed to update the repeatingInvoiceId provided in method but created a new repeating invoice #341

Open
yuruojie777 opened this issue May 23, 2023 · 1 comment

Comments

@yuruojie777
Copy link

// Create a repeating invoice
    @Test
    void testAddXeroRepeatingInvoice() throws Exception {
        String accessToken = xeroService.getToken();
        ApiClient defaultClient = new ApiClient();

        AccountingApi apiInstance = AccountingApi.getInstance(defaultClient);
        String xeroTenantId = xeroService.getTenantId();
        Boolean summarizeErrors = true;


        RepeatingInvoices repeatingInvoices = new RepeatingInvoices();
        RepeatingInvoice repeatingInvoice = new RepeatingInvoice();
        UUID invoiceId = UUID.randomUUID();
        System.out.println(invoiceId);
        repeatingInvoice.setRepeatingInvoiceID(invoiceId);
        Contact contact = new Contact();
        contact.setContactID(UUID.fromString("fe6f61ee-e6f1-4f32-b6fe-3486c6bac13c"));
        Schedule schedule = new Schedule();
        schedule.setUnit(Schedule.UnitEnum.WEEKLY);
        schedule.setStartDate(org.threeten.bp.LocalDate.now());
        schedule.setEndDate(org.threeten.bp.LocalDate.now().plusDays(3L));
        schedule.setPeriod(5);
        schedule.setDueDate(3);

        LineItem lineItem = new LineItem();
        lineItem.setQuantity(1.0);
        lineItem.setDescription("test");
        lineItem.setAccountCode("123456");
        lineItem.setUnitAmount(108.8);

        repeatingInvoice.setContact(contact);
        repeatingInvoice.setLineItems(List.of(lineItem));
        repeatingInvoice.setSchedule(schedule);
        repeatingInvoice.setType(RepeatingInvoice.TypeEnum.ACCREC);
        repeatingInvoice.setStatus(RepeatingInvoice.StatusEnum.AUTHORISED);

        repeatingInvoices.setRepeatingInvoices(List.of(repeatingInvoice));
        try {
            RepeatingInvoices result = apiInstance.createRepeatingInvoices(accessToken, xeroTenantId, repeatingInvoices, summarizeErrors);
            System.out.println(result);
        } catch (XeroException e) {
            System.err.println("Exception when calling AccountingApi#createRepeatingInvoices");
            e.printStackTrace();
        }
    }


// Update the repeating invoice based on the returned repeating invoice Id

@Test
    void testUpdateXeroRepeatingInvoice() throws IOException {
        String accessToken = xeroService.getToken();
        ApiClient defaultClient = new ApiClient();
        UUID repeatingInvoiceID = RETURNED REPEATING INVOICE ID
        AccountingApi apiInstance = AccountingApi.getInstance(defaultClient);
        String xeroTenantId = xeroService.getTenantId();
        RepeatingInvoices repeatingInvoices = new RepeatingInvoices();
        RepeatingInvoice repeatingInvoice = new RepeatingInvoice();
        Contact contact = new Contact();
        contact.setContactID(UUID.fromString("fe6f61ee-e6f1-4f32-b6fe-3486c6bac13c"));
        Schedule schedule = new Schedule();
        schedule.setUnit(Schedule.UnitEnum.MONTHLY);
        schedule.setStartDate(org.threeten.bp.LocalDate.now());
        schedule.setEndDate(org.threeten.bp.LocalDate.now().plusDays(10L));
        schedule.setPeriod(5);
        schedule.setDueDate(3);

        LineItem lineItem = new LineItem();
        lineItem.setQuantity(1.0);
        lineItem.setDescription("test");
        lineItem.setAccountCode("123456");
        lineItem.setUnitAmount(109.9);

        repeatingInvoice.setContact(contact);
        repeatingInvoice.setLineItems(List.of(lineItem));
        repeatingInvoice.setSchedule(schedule);
        repeatingInvoice.setType(RepeatingInvoice.TypeEnum.ACCREC);
        repeatingInvoice.setStatus(RepeatingInvoice.StatusEnum.AUTHORISED);
        repeatingInvoices.setRepeatingInvoices(List.of(repeatingInvoice));
        try {
            RepeatingInvoices result = apiInstance.updateRepeatingInvoices(accessToken, xeroTenantId, repeatingInvoiceID, repeatingInvoices);
            System.out.println(result);
        } catch (XeroException e) {
            System.err.println("Exception when calling AccountingApi#updateRepeatingInvoice");
            e.printStackTrace();
        }
    }

What I got in my Demo company is, every time I do updating, a new invoice will be created instead of replacing the previous one. But I can literally do updating repeating invoices mannually in Xero Demo company.

@icomputeUK
Copy link

Been trying to do similar by updating due dates in bulk.

But, I think UpdateRepeatingInvoice only creates new invoices or deletes them. As per the documentation here:

https://developer.xero.com/documentation/api/accounting/repeatinginvoices#overview

And the API Explorer here:

https://api-explorer.xero.com/accounting/repeatinginvoices/updaterepeatinginvoice?path-repeatinginvoiceid=

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants