Jump to content

Edit Invoice Via Model


Blesta Addons

Recommended Posts

when a invoice is edit, the Edit() function Delete existing unsent invoice delivery methods. so if we add/edit only the public note or private note the delivery method is not filled again . sample case

Create invoice with email delivery, try edit the invoice via model (plugin/api) in the same time (before the cron run, a better way is a event to test it on the fly), then the email delivery will be removed an no delivery is set again !! so the invoice will not send until we send it manually . i can't tell is a real bug, but is a bad behavior of editing the invoice via model, i think it should be marked in the docs to include the delivery var with the data set in edit.

something i think is similar to a previous behavior we have discovery with the invoice status, when we want to edit only a note or a lines, we should always send the status of the invoice to not be converted to active invoice when we use proforma .

 

Link to comment
Share on other sites

we will put a sample fix, so in our case we need to made something like that, in case anyone try to use the event triggers for invoice.add, all invoices edited  with the event Invoices.Add will end with no delivery method set .

// preserve the actual status
$vars['status'] = $invoice->status;
// Preserve the delivery method (in case of unsent invoice)
if (!empty($invoice->delivery)) {
	foreach ($invoice->delivery as $key => $value) {
		$vars['delivery'][] = ['method' => $value];
	}
}
$this->Invoices->edit($invoice->id, $vars);

 

Link to comment
Share on other sites

3 hours ago, Tyson said:

Yes, you'll need to provide the unsent delivery methods if you would like them to be maintained. The use of models will be updated in the future to provide better and more succinct actions for updates like these.

this is only affecting the unset invoice .

Link to comment
Share on other sites

Join the conversation

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

Guest
Reply to this topic...

×   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...