Skip to content

Conversation

@chienandalu
Copy link
Member

@chienandalu chienandalu commented Oct 22, 2025

There might be cases where we don't want to assign specific sequences to our
product and keep the core behavior. For that we've created a flag that allows
to do so.

  • The flag Use specific sequence is on by default.
  • Set it off and the product will behave as in Odoo core.
  • Once you do so, you can remove the product's lot sequence as well.

(TODO: remove this vídeo, as it's an old version of the change)
https://www.loom.com/share/4edde17a26ef4d2f9d909e59ea538f7b?sid=86bbaefb-926b-46a8-982f-c9b1a800e364

cc @moduon MT-12305

please review @rafaelbn @fcvalgar @Shide

@chienandalu chienandalu force-pushed the 16.0-imp-product_lot_sequence-ignore-auto branch from 66704b3 to aceb352 Compare October 22, 2025 09:16
@chienandalu chienandalu marked this pull request as ready for review October 22, 2025 11:17
Comment on lines 11 to 13
disallow_lot_sequence = fields.Boolean(
help="Don't use an specific lot sequence for this product"
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Would be great to have this variable inversed in meaning with a migration script.
Seems more readable and less confusing

Suggested change
disallow_lot_sequence = fields.Boolean(
help="Don't use an specific lot sequence for this product"
)
use_specific_lot_sequence = fields.Boolean(
help="Use an specific lot sequence for this product",
default=True,
)

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

Copy link
Member

@yajo yajo left a comment

Choose a reason for hiding this comment

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

IMHO the fact that checking (or unchecking, as per https://github.com/OCA/product-attribute/pull/2109/files#r2451880343) a checkbox removes or creates a record is a bit surprising.

I think that we can do a better UI:

Image

When removing, add a confirm="Are you sure?" or similar to the button.

This way, the effect and usability is nearly the same, but we avoid surprises.

There might be cases where we don't want to assign specific sequences to our
product and keep the core behavior. For that we've created a flag that allows
to do so.

- The flag *Use specific sequence* is on by default.
- Set it off and the product will behave as in Odoo core.
- Once you do so, you can remove the product's lot sequence as well.

MT-12305
@chienandalu chienandalu force-pushed the 16.0-imp-product_lot_sequence-ignore-auto branch from aceb352 to 325ec93 Compare October 23, 2025 08:37
@chienandalu chienandalu changed the title [16.0][IMP] product_lot_sequence: disallow product sequence [16.0][IMP] product_lot_sequence: product sequence exceptions Oct 23, 2025
@chienandalu chienandalu requested review from Shide and yajo October 23, 2025 08:40
@chienandalu
Copy link
Member Author

@Shide @yajo changes done. Take a look

Copy link

@fcvalgar fcvalgar left a comment

Choose a reason for hiding this comment

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

Functional Review,

LGTM, thank you @chienandalu

Copy link
Member

@yajo yajo left a comment

Choose a reason for hiding this comment

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

When creating a new product, I think this is inconsistent:

Image

Then, if you do this:

  1. Select "by lots"
  2. Create sequence
  3. Uncheck "use specific lot sequence".

You get another inconsistency:

Image

I think the problem is that the check box is now unnecessary. See comments below. If we remove the checkbox, it's gonna be less code and simpler UX.

Thanks!

Comment on lines +11 to +14
use_specific_lot_sequence = fields.Boolean(
help="Use an specific lot sequence for this product",
default=True,
)
Copy link
Member

Choose a reason for hiding this comment

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

This field can be removed now, and all other uses of it.

Since the creation or removal is done by buttons, then the presence or absence of a sequence is enough to make the module work.

Copy link
Member Author

Choose a reason for hiding this comment

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

No, because there's an automation that creates the sequence on every write if it isn't one and we want to avoid that (and I don't want to change that behavior that might affect other users of the module)

Copy link
Member

Choose a reason for hiding this comment

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

Even in that case, the behavior is inconsistent if we have 2 ways to do the same.

However, if that's the goal, there's an easier way to achieve it. Just add support for a new system parameter that disables the automatic creation of sequences, so if the user wants one, they just have to click on the create button.

Comment on lines -36 to +48
@api.depends("tracking") # For products being created (before saved).
@api.depends("tracking", "use_specific_lot_sequence")
def _compute_display_lot_sequence_fields(self):
self.display_lot_sequence_fields = (
product_sequence_policy = (
self.env["stock.lot"]._get_sequence_policy() == "product"
)
for product in self:
product.display_lot_sequence_fields = (
product_sequence_policy and product.use_specific_lot_sequence
)
Copy link
Member

Choose a reason for hiding this comment

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

This method should start by checking that if tracking == "none", then product.display_lot_sequence_fields = False.

Otherwise, just use the default value from config, since the checkbox should be removed.

product_sequence_policy and product.use_specific_lot_sequence
)

@api.model
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
@api.model

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants