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

[16.0][ADD] stock_picking_limit_return_qty #1424

Conversation

ivs-cetmix
Copy link
Member

Limit quantity of items that can be returned in the same picking

Before this PR:

User can return any amount of products in picking return. Even if this amount is more tha initial amount in the original picking.

After this PR:

if user tries to return bigger qty ot a product than it was in the original picking ValidationError is raised. This includes quantities already returned.

Comment on lines +22 to +26
_(
"You can return only %(max_qty)s of %(product)s",
max_qty=rec.quantity_max,
product=rec.product_id.name,
)

Choose a reason for hiding this comment

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

You need to wrap only "You can return only %(max_qty)s of %(product)s" argument.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hi @em230418 , thank you for your feedback! Actually current approach should work as well. Like it's described here

Translation terms are exported correctly as well
image

Choose a reason for hiding this comment

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

I see. Confused usage of % operator.

Comment on lines 76 to 86
error = "Error"
msg = ""
try:
line.quantity = line.quantity + 1
except ValidationError as e:
error = str(e)
msg = "You can return only %s of %s" % (
line.quantity_max,
line.product_id.name,
)
self.assertEqual(error, msg)

Choose a reason for hiding this comment

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

Maybe self.assertRaises(ValidationError) 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.

Fixed, please check

@rousseldenis rousseldenis added this to the 16.0 milestone Nov 13, 2023
Limit quantity of items that can be returned in the same picking
@DemchukM DemchukM force-pushed the 16.0-t2735-add-stock_picking_limit_return_qty-2 branch from 43c3f44 to a510b42 Compare November 15, 2023 12:46
@ivs-cetmix
Copy link
Member Author

@em230418 we have pushed the updates. Could you please do a code review again? Thank you in advance!

Copy link

@em230418 em230418 left a comment

Choose a reason for hiding this comment

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

Code looks fine. Didn't check functionality

Copy link
Contributor

@robinkeunen robinkeunen left a comment

Choose a reason for hiding this comment

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

Mostly good. View definition could be simpler if I'm not mistaken.

can you take a look at my PR? #1432

<field name="inherit_id" ref="stock.view_stock_return_picking_form" />
<field name="arch" type="xml">
<xpath
expr="//field[@name='product_return_moves']/tree/field[@name='quantity']"
Copy link
Contributor

Choose a reason for hiding this comment

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

I only see one quantity in the view, why not use the simpler field selector ?

<field name="quantity" position="after" />
        <field name="quantity_max" invisible="1" />
</field>

or even

<form position="inside" />
        <field name="quantity_max" invisible="1" />
</form>

Copy link
Member Author

Choose a reason for hiding this comment

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

Hi @robinkeunen thank you for your feedback! We opted for keeping them more explicit in case this module would be installed on some system which already has some modifications done in the same views.
To make it more capable of survival in a harsh module conditions)

Copy link
Contributor

Choose a reason for hiding this comment

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

Well, I think it's actually more robust to be more generic : <form> or <field name="quantity"> have more chance to survive the future than //field[@name='product_return_moves']/tree/field[@name='quantity'].

But ok :-)

Copy link

@Bearnard21 Bearnard21 left a comment

Choose a reason for hiding this comment

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

Functionality Ok

@OCA-git-bot
Copy link
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). 🤖

)._prepare_stock_return_picking_line_vals_from_move(stock_move)

# Store maximum quantity that is possible to return
res.update(
Copy link
Contributor

Choose a reason for hiding this comment

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

As this is breaking the default Odoo's behaviour, I would have added a configuration parameter to activate this.

Either a global one, either one on stock.picking.type object (I don't know if it is defined on stock move values at this point)

Copy link
Member Author

Choose a reason for hiding this comment

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

@rousseldenis thank you for mentioning this. Sounds reasonable. The only thing we didn't add it is because this is actually the only feature this module is adding. So this setting is actually if the module installed or not. Don't want this behaviour? Just uninstall it.
However the concern was that this module will be installed on the runboat bu default. So it might cause some confusion. It could be a good idea if this module could be installed as using checkbox in settings like this is done with some core Odoo modules. However I didn't manage to find to do the same for the third party modules.
Would be great if you could give some hints.

Copy link

There hasn't been any activity on this pull request in the past 4 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 30 days.
If you want this PR to never become stale, please ask a PSC member to apply the "no stale" label.

@github-actions github-actions bot added the stale PR/Issue without recent activity, it'll be soon closed automatically. label Apr 28, 2024
@github-actions github-actions bot closed this Jun 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs review stale PR/Issue without recent activity, it'll be soon closed automatically.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants