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

[MIG] product_multi_barcode: Migration to 16.0 #471

Merged
merged 25 commits into from
Apr 6, 2023

Conversation

StefanRijnhart
Copy link
Member

@StefanRijnhart StefanRijnhart commented Dec 2, 2022

From unmerged #434

This PR uncovers a problem with odoo-test-helper used in barcodes_generator_abstract's tests. This should be fixed in OCA/odoo-test-helper#22.

@StefanRijnhart StefanRijnhart added this to the 16.0 milestone Dec 2, 2022
@StefanRijnhart StefanRijnhart force-pushed the 16.0-mig-product_multi_barcode branch 3 times, most recently from a56fe4a to c4e15ad Compare December 2, 2022 14:03
@rousseldenis
Copy link
Sponsor Contributor

@StefanRijnhart Still draft ?

@rousseldenis
Copy link
Sponsor Contributor

/ocabot migration product_multi_barcode

@OCA-git-bot OCA-git-bot mentioned this pull request Feb 8, 2023
13 tasks
@StefanRijnhart
Copy link
Member Author

StefanRijnhart commented Feb 8, 2023

@rousseldenis waiting for the odoo-test-helper fix to get this one green. Thanks for checking that one! Now ready for review.

@StefanRijnhart StefanRijnhart marked this pull request as ready for review February 8, 2023 20:07
@StefanRijnhart
Copy link
Member Author

Pre-commit fixed here: #491

@OCA OCA deleted a comment from OCA-git-bot Feb 8, 2023
Copy link
Sponsor Contributor

@rousseldenis rousseldenis left a comment

Choose a reason for hiding this comment

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

Code review. Some performance improvements can be done.

[("id", "!=", record.id), ("name", "=", record.name)]
)
if barcodes:
raise UserError(
Copy link
Sponsor Contributor

Choose a reason for hiding this comment

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

You should use ValidationError in constraints

def _inverse_barcode(self):
for product in self:
if product.barcode_ids:
product.barcode_ids[:1].write({"name": product.barcode})
Copy link
Sponsor Contributor

Choose a reason for hiding this comment

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

I think write() is not correct in an inverse method. You should assign value instead.

Copy link
Member Author

Choose a reason for hiding this comment

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

I changed this, although I think write is fine in principle. The same method also uses create and unlink. But assigning a single attribute is more odoo-esque of course.

elif not product.barcode:
product.barcode_ids.unlink()
else:
self.env["product.barcode"].create(self._prepare_barcode_vals())
Copy link
Sponsor Contributor

Choose a reason for hiding this comment

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

Gather barcode vals in a list, then use multi create.

if product.barcode_ids:
product.barcode_ids[:1].write({"name": product.barcode})
elif not product.barcode:
product.barcode_ids.unlink()
Copy link
Sponsor Contributor

Choose a reason for hiding this comment

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

Gather barcode ids in a set(), then barcode_model.browse(ids).unlink()


@tagged("post_install", "-at_install")
class TestProductMultiBarcode(TransactionCase):
def setUp(self):
Copy link
Sponsor Contributor

Choose a reason for hiding this comment

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

Could you change this to classmethod ?

@api.constrains("name")
def _check_duplicates(self):
for record in self:
barcodes = self.search(

Choose a reason for hiding this comment

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

should use search_count?

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually, the found duplicate is used to present a detailed error message to the user so I've kept search.

elif not product.barcode:
product.barcode_ids.unlink()
else:
self.env["product.barcode"].create(self._prepare_barcode_vals())

Choose a reason for hiding this comment

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

should be product._prepare_barcode_vals()

Copy link

@aliciagaarzo aliciagaarzo left a comment

Choose a reason for hiding this comment

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

Review comments and cover all cases in tests.

@hugo-cordoba
Copy link

Hello @rousseldenis , I have seen that @aliciagaarzo has made the changes you requested, how do you see them? I think the development is correct, can we help to merge the code? Thank you very much, have a nice day.

@liebana
Copy link
Sponsor

liebana commented Mar 28, 2023

I've made a functional review and LGTM.

Friendly ping to @rousseldenis @StefanRijnhart @hieulucky111

@rousseldenis
Copy link
Sponsor Contributor

@StefanRijnhart Could you attend comments ?

Copy link
Sponsor Contributor

@rousseldenis rousseldenis left a comment

Choose a reason for hiding this comment

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

Code review

@StefanRijnhart
Copy link
Member Author

Thanks for the reviews. Fixes are now applied. I also included #501

@rousseldenis
Copy link
Sponsor Contributor

Thanks for the reviews. Fixes are now applied. I also included #501

@StefanRijnhart See my comment #501 (review)

@StefanRijnhart
Copy link
Member Author

@rousseldenis do you still have any remaining concerns, or are we ready for merge?

@rousseldenis
Copy link
Sponsor Contributor

/ocabot merge nobump

@OCA-git-bot
Copy link
Contributor

This PR looks fantastic, let's merge it!
Prepared branch 16.0-ocabot-merge-pr-471-by-rousseldenis-bump-nobump, awaiting test results.

@OCA-git-bot OCA-git-bot merged commit d3dfe58 into OCA:16.0 Apr 6, 2023
@OCA-git-bot
Copy link
Contributor

Congratulations, your PR was merged at 0346ada. Thanks a lot for contributing to OCA. ❤️

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.