Jump to content
Sign in to follow this  
Blesta Addons

Edit Invoice Via Model

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 .

 

Share this post


Link to post
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);

 

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
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 .

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×