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

Third party informations are not loaded when generating PDF from ODT in recurring invoice (via CRON only) #12395

Open
hminet opened this issue Nov 9, 2019 · 1 comment
Labels
Bug

Comments

@hminet
Copy link

@hminet hminet commented Nov 9, 2019

Bug

When running the CRON job to create the reccuring invoices (not affecting if you manually issue an invoice from a template via the web GUI).

If the reccuring invoice template uses as document template an ODT template (no issue if you use the crabe included PDF template) AND if you set the invoice template to save the invoice as DRAFT (not auto-validated) :

The third party name, address, and other informations are not loaded properly before document generation.

So on your generated PDF document you see no customer name, address, phone, VAT ID, etc... you have to manually regenerate the PDF afterwards from the invoice card...

This does not affect the invoices if you set the invoice template to auto-validate the generated invoices (status "to be paid").

Environment

Expected and actual behavior

The third party informations should be present in the object before the PDF document generation.

Steps to reproduce the behavior

  1. Create an ODT invoice template in which you use the fields : {company_name}, {company_address}, {company_zip}, {company_town}, {company_country}, {company_vatnumber} (i attach one example hereunder)

odt_invoice.odt.zip

  1. Create a template invoice for one of your customers and set this template like this :
  • Template : (your ODT template created in step 1)
  • Status of the generated invoices : Draft (to be validated)
  1. From the admin panel, in the admin tools > scheduled jobs, manually run the cron job for the recurring invoices (or let your CRON run it by itself)

  2. Check the generated invoice PDF document from the ODT... Third party informations will be missing !

@hminet hminet added the Bug label Nov 9, 2019
@hminet

This comment has been minimized.

Copy link
Author

@hminet hminet commented Nov 9, 2019

I have the solution but sorry I'm not used to GitHub yet so i could not make a pull request properly.

Fix :

File : /htdocs/compta/facture/class/facture-rec.class.php (around line 1171)

if (! $error && ($facturerec->auto_validate || $forcevalidation))
{
	$result = $facture->validate($user);
	if ($result <= 0)
	{
		$this->errors = $facture->errors;
		$this->error = $facture->error;
		$error++;
	}
}

modify as follows :

if (! $error && ($facturerec->auto_validate || $forcevalidation))
{
	$result = $facture->validate($user);
	if ($result <= 0)
	{
		$this->errors = $facture->errors;
		$this->error = $facture->error;
		$error++;
	}
}else {
	//load third party informations in the object for document generation
	$facture->fetch_thirdparty();
}

Indeed, the instruction $facture->fetch_thirdparty(); to load the third party informations in the object is not called if you leave the invoice as DRAFT (didn't choose to auto-validate the invoice).

However, tt is implicitely called in the $facture->validate() function if you have set in the template to automatically validate the generated invoices.

This will also call the function to load the third party informations in the invoice object even if you keep it as draft. So that your draft document is properly made with the third party informations.

@eldy : Can you please create a pull request by yourself to insert this fix in the code of the future releases ? I promise I will learn to better use GitHub in the near future :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.