Printing product serial numbers in Shipping doc

Hi. I am trying to get Dolibarr version 11.0.0 to show serial numbers of products in shipment delivery note document (odt and pdf).
Currently only the product identifier shows:

What I did was the following:

I included a computed attributed using complementary attributes (lines) in the shipping module that fetches serial numbers for each product prints them in a comma-separated list:

(($res = $db->query('select llx_equipement.ref from llx_equipement,llx_equipementevt where llx_equipementevt.fk_expedition = ‘.$object->lines[0]->fk_expedition.’ and llx_equipementevt.fk_equipement = llx_equipement.rowid and llx_equipement.fk_product = ‘.$object->lines[0]->fk_product)) && ($arr = $res->fetch_all()) ) ? implode(’, ', array_map(function ($entry) { return $entry[0]; }, $arr)) : ‘Reference number not found’

However, the attribute initially did not show. So what I did for a given shipment was add an entry for the shipment in the llx_expeditiondet_extrafields table:

`mysql> insert into llx_expeditiondet_extrafields(fk_object,testlineattrib) values(34,’’);
Query OK, 1 row affected (0.02 sec)

mysql> select * from llx_expeditiondet_extrafields;
±------±--------------------±----------±-----------±---------------+
| rowid | tms | fk_object | import_key | testlineattrib |
±------±--------------------±----------±-----------±---------------+
| 5 | 2020-02-25 09:56:21 | 34 | NULL | |
±------±--------------------±----------±-----------±---------------+
1 row in set (0.00 sec)
`

This made Dolibarr print the serial numbers for the products in the shipment doc for that given shipment only (both in expedition/card.php page and in generated odt doc).

It seems that the serial numbers would show in the shipment doc for just the shipments that have entries in the llx_expeditiondet_extrafields table, and not for other shipments.

Obviously, manually adding entries for shipments in the llx_expeditiondet_extrafields table is not a viable solution. Kindly guide me as to how I can remedy this issue. Thanks in advance.

For displaying serial numbers for multiple products in a single shipment the following can be used instead of what is in the original post:

(($res = $db->query('select llx_equipement.ref from llx_equipement,llx_equipementevt where llx_equipementevt.fk_expedition = ‘.$object->lines[0]->fk_expedition.’ and llx_equipementevt.fk_equipement = llx_equipement.rowid and llx_equipement.fk_product = ‘.$object->lines[ isset($GLOBALS[‘xjkvn’]) ? ++$GLOBALS[‘xjkvn’] : $GLOBALS[‘xjkvn’] = 0 ]->fk_product)) && ($arr = $res->fetch_all()) ) ? implode(’, ', array_map(function ($entry) { return $entry[0]; }, $arr)) : ‘Reference number not found’

One way of addressing this issue is to add code in expedition/card.php that would add the shipment to the llx_expeditiondet_extrafields table, before the complementary attributes are fetched.

Don’t know if there is a better alternative to such a hack.

Same Shipping doc generated (from original post) with serial numbers included: