Extra Fields on Sales Order pdf

I’m using Dolibarr 12.0.4 and testing 13

Getting extra fields on pdf is now provided in these versions and a wiki page is present:

I’m following this wiki step by step to add a module complementary attribute. I even named the extra field/attribute exactly the same as in the wiki. The only difference is that I’m trying to achieve this on a sales order (template einstein is used as source) and not on an invoice.

Given code is copied and pasted as stated. The extra field will not show.

Hello,

Have you tried eratosthene model ?
It normally includes extrafields automatically

Tried it out of the box. No Extra fields shown.
Then I modify the template as stated in the wiki. No results either.

My goal is to add some Product extrafields on Sales Order Line

Hello,

The Extrafields that are automatically displayed is Extrafields of the object.

If you want to display product Extrafields on sales orders you should follow the wiki.

If you would like help you need to describe what you have done

Hi @ksar,

Thanks for offering some help.
These are the steps (its a staging area so for testing purposes I’m editing source files):

  1. created a complementary attribute on the products and services module with attribute code artiest
  2. used the wiki as guide
  3. modified /core/modules/commande/doc/pdf_eratosthene.modules.php
  4. on line 38 added
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
  1. on line 290+291 added after
$object->fetch_thirdparty();
$extrafieldsline = new ExtraFields($this->db);
$extralabelsline=$extrafieldsline->fetch_name_optionals_label($object->table_element_line);
  1. on line 560 added
					if ($object->lines[$i]->fk_product)
					{
						require_once (DOL_DOCUMENT_ROOT."/product/class/product.class.php");
						$product = new Product($this->db);
						$product->fetch($object->lines[$i]->fk_product);

						$extrafields_product = new ExtraFields($this->db);
						$extralabels_product = $extrafields_product->fetch_name_optionals_label($product->table_element);

						$product->fetch_optionals($product->rowid, $extralabels_product);
					}
  1. on line 653 added
$pdf->MultiCell(0, 3, $outputlangs->convToOutputCharset($product->lines[$i]->array_options['options_artiest']), 0, 'L', 0);

used before $posYAfterDescription = $pdf->GetY();

Hi,

This line is wrong :

Should be something like :

$pdf->MultiCell(0, 3, $outputlangs->convToOutputCharset($product->array_options['options_artiest']), 0, 'L', 0);

Thanks. That did the trick.

My line is a copy from the wiki. So this has to be changed in the wiki.

Sorry but the Wiki is OK :

$outputlangs->convToOutputCharset($product->array_options['options_my_product_extra'])

You’re absolutely right. My bad.

When I look at the wiki it is possible to display the label of a value from a selectlist. But when I paste the code I get a 500 Error.

I replaced the code:
$pdf->MultiCell(0, 3, $outputlangs->convToOutputCharset($product->array_options['options_formaat']), 0, 'L', 0);

with
$pdf->MultiCell(0, 3, $extrafields->showOutputField('formaat', $object->array_options['options_formaat']), 0, 'L', 0);

Hello,

Could you check the logs to see what is the issue ?

Nothing to see in the logs.

I think it’s a syntax error in the PDF.

Hi,

For error 500, you need to check your hosting logs not the Dolibarr logs.

Offcourse. Here it is.

Hello,

The error is :

PHP Fatal error: Uncaught Error: Call to a member function showOutputField() on null in…

Meaning that $extrafields or $object->array_options['options_formaat'] is empty
Check how this two variables are created.

Found the error.
I wanted to display a product attribute/extra field. So I had to replace some code from the example in the wiki. This is the correct code to display the label and not the value:

$extrafields_product->showOutputField('my_extra', $product->array_options['options_my_extra']);

I changed: $extrafields in $extrafields_product
I changed: $object->array_options in $product->array_options

@ksar: Thanks for all the help

1 Like