Jump to content
  • 0

Unable To Edit Invoice To Delete Line Items Via Api


Question

Posted

Example API call:

 

php /var/www/index.php api/invoices/edit.json -u <user> -k <key> -m POST -p invoice_id=<invoice_id>&vars%5Blines%5D%5B0%5D%5Bid%5D=<invoice_line_id>

 

Expected behavior:

 

Line item is deleted from invoice.

 

Actual behavior:

 

Failure due to an empty description for the line item

 

The below patch allows the line item to be deleted.

 

diff --git a/app/models/invoices.php b/app/models/invoices.php
index 30e6925..7ce7fe6 100644
--- a/app/models/invoices.php
+++ b/app/models/invoices.php
@@ -387,6 +387,8 @@ class Invoices extends AppModel {
         // No lines set, no descriptions required
         if (!isset($vars['lines'])) {
             $vars['lines'] = array();
+        }
+        if(empty($vars['lines'])) {
             $line_rules['lines[][description]']['empty']['if_set'] = true;
         }
         // If status is proforma, but changing to active, amounts are likely applied, and the amount applied rule can be ignored
@@ -447,7 +449,7 @@ class Invoices extends AppModel {
                     $this->addDelivery($invoice_id, array('method'=>$vars['delivery'][$i]), $vars['client_id']);
             }
             
-            if (!empty($vars['lines'])) {
+            if (!empty($vars['lines']) || !empty($delete_items)) {
                 // Get the tax rules
                 $tax_rules = $this->getTaxRules($invoice->client_id);
                 
@@ -523,7 +525,7 @@ class Invoices extends AppModel {
                     $this->unsetMeta($invoice_id);
             }
             
-            if (!empty($vars['lines'])) {
+            if (!empty($vars['lines']) || !empty($delete_items)) {
                 // Update totals/set closed status
                 $this->setClosed($invoice_id);
             }
 

1 answer to this question

Recommended Posts

  • 0
Posted

I'm not sure why you included a diff of some code from the Invoices model, but if you want to delete an invoice line item, you should pass in the invoice line item ID, an empty amount, and an empty description.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...