Skip to content

[18.0][FIX] delivery_postlogistics: Fix package id on label - #1044

Closed
wouitmil wants to merge 70 commits into
OCA:18.0from
camptocamp:fix-package_id-on-label
Closed

[18.0][FIX] delivery_postlogistics: Fix package id on label#1044
wouitmil wants to merge 70 commits into
OCA:18.0from
camptocamp:fix-package_id-on-label

Conversation

@wouitmil

Copy link
Copy Markdown

Ensure that the package_id is set

It's needed when stock_picking._generate_postlogistics_label is called from a generate_label on a stock_picking_batch

Ricardoalso and others added 30 commits August 21, 2025 13:46
- change name to batch to match with change of `picking_dispatch` name to
`stock_batch_picking`
- mode description in README.rst
- move files in models and views directories
- change headers to small license header
- use api 8.0
- fix and improve tests
the field has been renamed in the base module
Probably due to usage of multiple environment and cache. datas can't be
read from shipping.label but it can be read from ir.attachment
When there is more than 1 pack in a picking, 2 or more thread worker
might be in concurrence on the same picking, which makes one of the
transaction fails, resulting in the abort of the whole label generation.

The solution implemented is to change the way of passing the tasks to
the thread workers. Instead of passing a label at a time, we pass a
group of label. A group of label actually contains all the labels to
generate for one picking.
Co-Authored-By: Alexandre Fayolle <alexandre.fayolle@camptocamp.com>
grindtildeath and others added 23 commits August 21, 2025 13:46
The threading option doesn't work in test mode but was not tested
because labels were already generated in the test.
Using a condition to use different threads only when test mode
is not activated allows to test label generation.
Co-authored-by: Hai Lang <hailn@trobz.com>
Sometimes, when regenerating labels from third party API, we could not get the
new tracking references. And then as we do not purge tracking references
correctly, previous ones are kept and lead to incoherences (batch picking
tracking references emptied but labels still existing). For this we need to
manually purge references when asking for full regeneration.
Updated by "Update PO files to match POT (msgmerge)" hook in Weblate.

Translation: delivery-carrier-14.0/delivery-carrier-14.0-delivery_carrier_label_batch
Translate-URL: https://translation.odoo-community.org/projects/delivery-carrier-14-0/delivery-carrier-14-0-delivery_carrier_label_batch/
Currently translated at 2.8% (1 of 35 strings)

Translation: delivery-carrier-14.0/delivery-carrier-14.0-delivery_carrier_label_batch
Translate-URL: https://translation.odoo-community.org/projects/delivery-carrier-14-0/delivery-carrier-14-0-delivery_carrier_label_batch/es/
Currently translated at 100.0% (35 of 35 strings)

Translation: delivery-carrier-14.0/delivery-carrier-14.0-delivery_carrier_label_batch
Translate-URL: https://translation.odoo-community.org/projects/delivery-carrier-14-0/delivery-carrier-14-0-delivery_carrier_label_batch/es/
…er_code`

    This line has been added by OCA@3b0232d but it looks like the field carrier_code has never been added to the model (or at least it has never been merged in the OCA repo?), thus we get following error when updating the ``carrier_id``:
    ```
    [...]
      File "/odoo/src/addons/web/models/models.py", line 1005, in onchange
        record._apply_onchange_methods(field_name, result)
      File "/odoo/src/odoo/models.py", line 7364, in _apply_onchange_methods
        res = method(self)
              ^^^^^^^^^^^^
      File "/odoo/external-src/delivery-carrier/delivery_carrier_label_batch/models/stock_batch_picking.py", line 61, in onchange_carrier_id
        self.carrier_code = self.carrier_id.code
        ^^^^^^^^^^^^^^^^^
    AttributeError: 'stock.picking.batch' object has no attribute 'carrier_code'

    The above server error caused the following client error:
    RPC_ERROR: Odoo Server Error
        RPC_ERROR
            at makeErrorFromResponse (http://localhost:8069/web/assets/e5ed061/web.assets_web.min.js:3144:163)
            at XMLHttpRequest.<anonymous> (http://localhost:8069/web/assets/e5ed061/web.assets_web.min.js:3149:13)
    ```
… by ``UserError.args[0]``

In the label generation, when getting an error, we were using its ``name``, however, this is deprecated since a while and as been removed in odoo/odoo@d200dcf.
We should use ``args[0]`` instead.
… return ``stock.move.line`` records instead of an Iterator

All calls to this method expect ``stock.move.line`` records.
Regenerating the carrier labels would crash with a Concurent Update
error.

We use a new cursor for tracking reference purge and avoid concurrent update
when the labels regeneration also updates that field in a separate
cursor afterwards: this ensures that the purge is committed before the
transactions created by the threads also update and commit their own
changes.
Don't spawn more threads than needed: if there are fewer groups to
process than the configured max number of threads, only start the
specified number of threads.
@wouitmil
wouitmil force-pushed the fix-package_id-on-label branch 3 times, most recently from fc9ff96 to 754d31e Compare August 28, 2025 21:32
@wouitmil wouitmil closed this Aug 28, 2025
@wouitmil
wouitmil deleted the fix-package_id-on-label branch August 28, 2025 21:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.