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

[18.0] [MIG] delivery_postlogistics_dangerous_goods: Migration to 18.0 #941

Open
wants to merge 12 commits into
base: 18.0
Choose a base branch
from

Conversation

bizzappdev
Copy link

@bizzappdev bizzappdev commented Jan 28, 2025

Dependency MR for module l10n_eu_product_adr_dangerous_goods OCA/community-data-files#211

Dependency MR for module delivery_postlogistics #974

@bizzappdev bizzappdev force-pushed the 18.0-mig-delivery_postlogistics_dangerous_goods-BAD branch 3 times, most recently from 4cf732f to 7c767f0 Compare January 28, 2025 11:16
@bizzappdev bizzappdev marked this pull request as ready for review February 5, 2025 07:45
@@ -30,6 +30,7 @@ def setUpClassWebservice(cls):
cls.service_class = PostlogisticsWebServiceDangerousGoods(
cls.env.user.company_id
)
return None

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it the same without it?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return will be needed as we are calling super, else pre-commit will fail.
So, we return the super result now.

@bizzappdev bizzappdev marked this pull request as draft February 5, 2025 14:41
@bizzappdev bizzappdev force-pushed the 18.0-mig-delivery_postlogistics_dangerous_goods-BAD branch from 7c767f0 to f8e50f0 Compare February 6, 2025 06:45
@bizzappdev bizzappdev marked this pull request as ready for review February 6, 2025 06:47
@rousseldenis
Copy link
Contributor

/ocabot migration delivery_postlogistics_dangerous_goods

@OCA-git-bot OCA-git-bot added this to the 18.0 milestone Feb 6, 2025
@OCA-git-bot OCA-git-bot mentioned this pull request Feb 6, 2025
24 tasks
@bizzappdev bizzappdev force-pushed the 18.0-mig-delivery_postlogistics_dangerous_goods-BAD branch from f8e50f0 to fc34c3a Compare February 10, 2025 05:40
@bizzappdev bizzappdev force-pushed the 18.0-mig-delivery_postlogistics_dangerous_goods-BAD branch from fc34c3a to 1d445f5 Compare February 17, 2025 10:17
@StephaneMangin
Copy link

@bizzappdev Module delivery_postlogistics is up and green, you can rebase safely

@bizzappdev bizzappdev force-pushed the 18.0-mig-delivery_postlogistics_dangerous_goods-BAD branch from 1d445f5 to 580520e Compare March 20, 2025 05:13
@rousseldenis
Copy link
Contributor

@bizzappdev Could you fix tests ? It seems a method does not exist

@StephaneMangin
Copy link

StephaneMangin commented Mar 20, 2025

@bizzappdev Could you fix tests ? It seems a method does not exist

Yes please use _get_quant_packages_from_picking instead (packages exists in two different models stock.quant.package, used here and product.packaging)

Comment on lines 11 to 44
class PostlogisticsWebServiceDangerousGoods(web_service.PostlogisticsWebService):
def _get_unnumbers(self, picking, pack=None):
"""
If any dangerous goods with limited quantity, returns a list of UNNumbers.
"""
products = (
pack
and pack.mapped("quant_ids.product_id")
or picking.mapped("move_ids.product_id")
)
limited_amount_lq = picking.env.ref(
"l10n_eu_product_adr_dangerous_goods.limited_amount_1"
)
limited_quantity_products = products.filtered(
lambda p: p.is_dangerous and p.limited_amount_id == limited_amount_lq
)
# Since 14.0, un numbers checks are done directly in l10n_eu_product_adr
return [
int(product.adr_goods_id.un_number) for product in limited_quantity_products
]

def _prepare_attributes(
self, picking, pack=None, pack_num=None, pack_total=None, pack_weight=None
):
# Adds a new attribute UNNumbers when there's dangerous goods
# in the pack / picking
res = super()._prepare_attributes(
picking, pack, pack_num, pack_total, pack_weight
)
unnumbers = self._get_unnumbers(picking, pack)
if unnumbers:
res.setdefault("przl", []).append("LQ")
res["unnumbers"] = unnumbers
return res

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I update the delivery_postlogistics API to implement these method in stock.picking and avoid overriding this webservice which is not meant to be overridden with multiple module that could not be chained properly.
Please see implementation in stock.picking

For instance replace in stock.picking by:

    def _get_unnumbers(self, pack=None):
        """
        If any dangerous goods with limited quantity, returns a list of UNNumbers.
        """
        self.ensure_one()
        products = (
            pack
            and pack.mapped("quant_ids.product_id")
            or self.mapped("move_ids.product_id")
        )
        limited_amount_lq = self.env.ref(
            "l10n_eu_product_adr_dangerous_goods.limited_amount_1"
        )
        limited_quantity_products = products.filtered(
            lambda p: p.is_dangerous and p.limited_amount_id == limited_amount_lq
        )
        # Since 14.0, un numbers checks are done directly in l10n_eu_product_adr
        return [
            int(product.adr_goods_id.un_number) for product in limited_quantity_products
        ]

    def postlogistics_label_prepare_attributes(
        self, pack=None, pack_num=None, pack_total=None, pack_weight=None
    ):
        # Adds a new attribute UNNumbers when there's dangerous goods
        # in the pack / picking
        res = super().postlogistics_label_prepare_attributes(
            pack, pack_num, pack_total, pack_weight
        )
        unnumbers = self._get_unnumbers(pack)
        if unnumbers:
            res.setdefault("przl", []).append("LQ")
            res["unnumbers"] = unnumbers
        return res

Comment on lines 12 to 38
def _generate_postlogistics_label(
self, webservice_class=None, package_ids=None, skip_attach_file=False
):
"""Generate post logistic label using specific from this module."""
if webservice_class is None:
webservice_class = PostlogisticsWebServiceDangerousGoods
return super()._generate_postlogistics_label(
webservice_class=webservice_class,
package_ids=package_ids,
skip_attach_file=skip_attach_file,
)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def _generate_postlogistics_label(
self, webservice_class=None, package_ids=None, skip_attach_file=False
):
"""Generate post logistic label using specific from this module."""
if webservice_class is None:
webservice_class = PostlogisticsWebServiceDangerousGoods
return super()._generate_postlogistics_label(
webservice_class=webservice_class,
package_ids=package_ids,
skip_attach_file=skip_attach_file,
)
def _get_unnumbers(self, pack=None):
"""
If any dangerous goods with limited quantity, returns a list of UNNumbers.
"""
self.ensure_one()
products = (
pack
and pack.mapped("quant_ids.product_id")
or self.mapped("move_ids.product_id")
)
limited_amount_lq = self.env.ref(
"l10n_eu_product_adr_dangerous_goods.limited_amount_1"
)
limited_quantity_products = products.filtered(
lambda p: p.is_dangerous and p.limited_amount_id == limited_amount_lq
)
# Since 14.0, un numbers checks are done directly in l10n_eu_product_adr
return [
int(product.adr_goods_id.un_number) for product in limited_quantity_products
]
def postlogistics_label_prepare_attributes(
self, pack=None, pack_num=None, pack_total=None, pack_weight=None
):
# Adds a new attribute UNNumbers when there's dangerous goods
# in the pack / picking
res = super().postlogistics_label_prepare_attributes(
pack, pack_num, pack_total, pack_weight
)
unnumbers = self._get_unnumbers(pack)
if unnumbers:
res.setdefault("przl", []).append("LQ")
res["unnumbers"] = unnumbers
return res

Comment on lines 27 to 33
@classmethod
def setUpClassWebservice(cls):
res = super().setUpClassWebservice()
cls.service_class = PostlogisticsWebServiceDangerousGoods(
cls.env.user.company_id
)
return res

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@classmethod
def setUpClassWebservice(cls):
res = super().setUpClassWebservice()
cls.service_class = PostlogisticsWebServiceDangerousGoods(
cls.env.user.company_id
)
return res

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can safely remove when implementation is updated

# no unnumber should be sent through the api
products = [(self.product_no_lq, 10.0)]
picking = self.create_picking(product_matrix=products)
package_ids = picking._get_packages_from_picking()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
package_ids = picking._get_packages_from_picking()
package_ids = picking._get_quant_packages_from_picking()

# we should have the list of unnumbers
products = [(self.dangerous_weapon, 10.0)]
picking = self.create_picking(product_matrix=products)
package_ids = picking._get_packages_from_picking()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
package_ids = picking._get_packages_from_picking()
package_ids = picking._get_quant_packages_from_picking()

@bizzappdev bizzappdev force-pushed the 18.0-mig-delivery_postlogistics_dangerous_goods-BAD branch from 580520e to 18a8def Compare March 21, 2025 06:11
Copy link

@StephaneMangin StephaneMangin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A last update and it will be all good ^^

products = [(self.product_no_lq, 10.0)]
picking = self.create_picking(product_matrix=products)
package_ids = picking._get_quant_packages_from_picking()
recipient = self.service_class._prepare_recipient(picking)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
recipient = self.service_class._prepare_recipient(picking)
recipient = picking.postlogistics_label_prepare_recipient()

products = [(self.dangerous_weapon, 10.0)]
picking = self.create_picking(product_matrix=products)
package_ids = picking._get_quant_packages_from_picking()
recipient = self.service_class._prepare_recipient(picking)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
recipient = self.service_class._prepare_recipient(picking)
recipient = picking.postlogistics_label_prepare_recipient()

@StephaneMangin
Copy link

@BhaveshHeliconia A last rebase and it's all good ^^ Sorry for the inconvenience, it's been a bit unhandy these days...

@bizzappdev bizzappdev force-pushed the 18.0-mig-delivery_postlogistics_dangerous_goods-BAD branch from 18a8def to f36f450 Compare March 22, 2025 07:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants