Jump to content
  • 0

Unable To Edit Invoice To Delete Line Items Via Api


srn

Question

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);
             }
 

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...