Skip to content

[16.0][IMP] sale_packaging_default: Add context to support bypass setting default packaging#3249

Draft
QuocDuong1306 wants to merge 1 commit intoOCA:16.0from
QuocDuong1306:16.0-imp-sale_packaging_default
Draft

[16.0][IMP] sale_packaging_default: Add context to support bypass setting default packaging#3249
QuocDuong1306 wants to merge 1 commit intoOCA:16.0from
QuocDuong1306:16.0-imp-sale_packaging_default

Conversation

@QuocDuong1306
Copy link
Copy Markdown

In some cases, we don't want to get the default for packaging. This PR will provide a context to use for those cases.

@OCA-git-bot
Copy link
Copy Markdown
Contributor

Hi @yajo,
some modules you are maintaining are being modified, check this out!

@yajo
Copy link
Copy Markdown
Member

yajo commented Jul 25, 2024

In which cases?

@QuocDuong1306 QuocDuong1306 force-pushed the 16.0-imp-sale_packaging_default branch from 2d72167 to f128b8f Compare July 26, 2024 07:31
@QuocDuong1306
Copy link
Copy Markdown
Author

QuocDuong1306 commented Jul 26, 2024

In which cases?

Hi @yajo , this context will be helpful for those cases:

  • With specific products, users don't want to get the default for product packaging but keep using the default for others.
  • Or using sale_packaging_default and sell_only_by_packaging together in 1 DB, using this context in the glue module will help for the force quantities feature

@yajo
Copy link
Copy Markdown
Member

yajo commented Jul 29, 2024

  • With specific products, users don't want to get the default for product packaging but keep using the default for others.

If this is your use case, have you considered simply prepending a packaging of 1 to the list of packagings? It will be used by default in that product and give you the default Odoo behavior without any extra code.

Otherwise, the fix is incomplete, as this won't allow a product to do that.

  • Or using sale_packaging_default and sell_only_by_packaging together in 1 DB, using this context in the glue module will help for the force quantities feature

If this is your case, I think it is more appropriate to add this is in the PR where you add the glue module. Or at least, to keep it as draft until you open such PR. And please add some tests.

@api.depends("product_id", "product_uom_qty", "product_uom")
def _compute_product_packaging_id(self):
"""Set a default packaging for sales if possible."""
if not self.env.context.get("apply_default_packaging", True):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Depending on context for stored fields is usually bad. Maybe you can explain a little bit your use case ?

Copy link
Copy Markdown
Contributor

@rousseldenis rousseldenis Aug 20, 2024

Choose a reason for hiding this comment

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

But I see @yajo has already asked.

@QuocDuong1306
Copy link
Copy Markdown
Author

Or using sale_packaging_default and sell_only_by_packaging together in 1 DB, using this context in the glue module will help for the force quantities feature

Hello @yajo @rousseldenis , actually, this is my case

If this is your case, I think it is more appropriate to add this is in the PR where you add the glue module. Or at least, to keep it as draft until you open such PR. And please add some tests.

I'll double-check for this one. Temporarily, marking this PR as Draft is a good idea. Thanks

@QuocDuong1306 QuocDuong1306 marked this pull request as draft August 23, 2024 03:19
@cyrilmanuel
Copy link
Copy Markdown

@QuocDuong1306 any new on that PR ? can we go on with that ?

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.

5 participants