-
-
Notifications
You must be signed in to change notification settings - Fork 366
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
base: 18.0
Are you sure you want to change the base?
[18.0] [MIG] delivery_postlogistics_dangerous_goods: Migration to 18.0 #941
Conversation
4cf732f
to
7c767f0
Compare
@@ -30,6 +30,7 @@ def setUpClassWebservice(cls): | |||
cls.service_class = PostlogisticsWebServiceDangerousGoods( | |||
cls.env.user.company_id | |||
) | |||
return None |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
7c767f0
to
f8e50f0
Compare
/ocabot migration delivery_postlogistics_dangerous_goods |
f8e50f0
to
fc34c3a
Compare
fc34c3a
to
1d445f5
Compare
@bizzappdev Module delivery_postlogistics is up and green, you can rebase safely |
1d445f5
to
580520e
Compare
@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) |
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 |
There was a problem hiding this comment.
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
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, | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
@classmethod | ||
def setUpClassWebservice(cls): | ||
res = super().setUpClassWebservice() | ||
cls.service_class = PostlogisticsWebServiceDangerousGoods( | ||
cls.env.user.company_id | ||
) | ||
return res |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@classmethod | |
def setUpClassWebservice(cls): | |
res = super().setUpClassWebservice() | |
cls.service_class = PostlogisticsWebServiceDangerousGoods( | |
cls.env.user.company_id | |
) | |
return res |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
package_ids = picking._get_packages_from_picking() | |
package_ids = picking._get_quant_packages_from_picking() |
580520e
to
18a8def
Compare
There was a problem hiding this 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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
recipient = self.service_class._prepare_recipient(picking) | |
recipient = picking.postlogistics_label_prepare_recipient() |
@BhaveshHeliconia A last rebase and it's all good ^^ Sorry for the inconvenience, it's been a bit unhandy these days... |
Currently translated at 100.0% (4 of 4 strings) Translation: delivery-carrier-14.0/delivery-carrier-14.0-delivery_postlogistics_dangerous_goods Translate-URL: https://translation.odoo-community.org/projects/delivery-carrier-14-0/delivery-carrier-14-0-delivery_postlogistics_dangerous_goods/es/
18a8def
to
f36f450
Compare
Dependency MR for module
l10n_eu_product_adr_dangerous_goods
OCA/community-data-files#211Dependency MR for module
delivery_postlogistics
#974