Skip to content

[16.0][ADD] new simple module for bulk product#2259

Merged
OCA-git-bot merged 1 commit intoOCA:16.0from
grap:16.0-ADD-product_is_bulk-QD
Apr 28, 2026
Merged

[16.0][ADD] new simple module for bulk product#2259
OCA-git-bot merged 1 commit intoOCA:16.0from
grap:16.0-ADD-product_is_bulk-QD

Conversation

@quentinDupont
Copy link
Copy Markdown

@quentinDupont quentinDupont commented Apr 13, 2026

In a context of organic groceries selling lot of bulk products, we need to quickly identify them so this module adds this simple computed (and inverse) field

image

@quentinDupont quentinDupont force-pushed the 16.0-ADD-product_is_bulk-QD branch from 906a9c4 to bcb7c09 Compare April 14, 2026 07:41
Copy link
Copy Markdown

@MDgrap MDgrap left a comment

Choose a reason for hiding this comment

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

Tested with runboat, works as intended

Copy link
Copy Markdown
Contributor

@legalsylvain legalsylvain left a comment

Choose a reason for hiding this comment

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

hi. thanks for your contribution !
some remarks inline. a blocking one regarding onchange / computed.

Otherwise, LGTM.
thanks !

Comment on lines +11 to +20
is_bulk = fields.Boolean()

# Onchange Section
@api.onchange("uom_id")
def onchange_uom_id(self):
self.is_bulk = (
True
if self.uom_id.category_id.measure_type in ["weight", "volume"]
else False
)
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.

Suggested change
is_bulk = fields.Boolean()
# Onchange Section
@api.onchange("uom_id")
def onchange_uom_id(self):
self.is_bulk = (
True
if self.uom_id.category_id.measure_type in ["weight", "volume"]
else False
)
is_bulk = fields.Boolean(compute="_compute_is_bulk", readonly=False)
@api.depends("uom_id.category_id.measure_type")
def _compute_is_bulk(self):
for product in self:
product.is_bulk = product.uom_id.category_id.measure_type in ["weight", "volume"]

Better to replace by a computed function (readonly = False). As a result, the code will be raised in more moment. for exemple,

  • if we import product massively, computation will be done. (it is not the case I think if it's onchange).
  • when installing the module, the computation will be done for all existing product.

WDYT ?

Note : maybe it is requiring an SQL script to initialize more quickly the database...)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I chose onchange by simplicity because we also want to handle few cases where product is bulk but is not marked for sale by weight : e.g cookies sold in bulk in a jar, the price being by unit.

But indeed, maybe we can go "compute" and add an inverse function

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Weird, my PR description talks about compute and inverse function, maybe that was my first idea ^^

Comment on lines +26 to +29
# Onchange Section
@api.onchange("uom_id")
def onchange_uom_id(self):
ProductProduct.onchange_uom_id(self)
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.

Suggested change
# Onchange Section
@api.onchange("uom_id")
def onchange_uom_id(self):
ProductProduct.onchange_uom_id(self)

def test_01_change_uom(self):
self.assertEqual(self.product1.is_bulk, False)
self.product1.uom_id = self.uom_kg
self.product1.onchange_uom_id()
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.

Suggested change
self.product1.onchange_uom_id()

class ProductProduct(models.Model):
_inherit = "product.product"

is_bulk = fields.Boolean()
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.

I think that an helper could be great for that field. somethink like

help="Check this box if this product is sold without any manufactured packaging. It is usually the case for product whose unit of measure is a unit of weight or volume, but it can be also the case for products priced per unit but sold in bulk (such as cookies, bread, etc.)"

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

ok you had the same example :-p

Copy link
Copy Markdown
Contributor

@legalsylvain legalsylvain left a comment

Choose a reason for hiding this comment

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

I think it will work the same, and be more synthetic.

Comment on lines +30 to +31
def _inverse_is_bulk(self):
pass
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.

Suggested change
def _inverse_is_bulk(self):
pass


is_bulk = fields.Boolean(
compute="_compute_is_bulk",
inverse="_inverse_is_bulk",
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.

Suggested change
inverse="_inverse_is_bulk",
readonly=False,

@quentinDupont quentinDupont force-pushed the 16.0-ADD-product_is_bulk-QD branch from 2d8e550 to b559aa3 Compare April 28, 2026 14:34
@quentinDupont quentinDupont force-pushed the 16.0-ADD-product_is_bulk-QD branch from b559aa3 to e2c8bcb Compare April 28, 2026 14:41
Copy link
Copy Markdown
Contributor

@legalsylvain legalsylvain left a comment

Choose a reason for hiding this comment

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

thanks !

@OCA-git-bot
Copy link
Copy Markdown
Contributor

This PR has the approved label and has been created more than 5 days ago. It should therefore be ready to merge by a maintainer (or a PSC member if the concerned addon has no declared maintainer). 🤖

@legalsylvain
Copy link
Copy Markdown
Contributor

/ocabot merge nobump

@OCA-git-bot
Copy link
Copy Markdown
Contributor

What a great day to merge this nice PR. Let's do it!
Prepared branch 16.0-ocabot-merge-pr-2259-by-legalsylvain-bump-nobump, awaiting test results.

@OCA-git-bot OCA-git-bot merged commit 53d0c72 into OCA:16.0 Apr 28, 2026
9 checks passed
@OCA-git-bot
Copy link
Copy Markdown
Contributor

Congratulations, your PR was merged at f698b81. 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.

4 participants