-
Notifications
You must be signed in to change notification settings - Fork 1
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
[4947][ADD] purchase_stock_price_variance #107
base: 16.0
Are you sure you want to change the base?
[4947][ADD] purchase_stock_price_variance #107
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Partial review.
inventory_price_check
doesn't seem to follow the normal naming convention. How about purchase_stock_price_variance
as the module name?
price_discrepancy_threshold_type = fields.Selection( | ||
[("percentage", "Percentage"), ("fixed", "Fixed Value"), ("ignore", "Ignore")] | ||
) | ||
price_discrepancy_threshold_value = fields.Float( | ||
help="Threshold value for price discrepancy warnings." | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make it like this:
price_discrepancy_threshold_type = fields.Selection( | |
[("percentage", "Percentage"), ("fixed", "Fixed Value"), ("ignore", "Ignore")] | |
) | |
price_discrepancy_threshold_value = fields.Float( | |
help="Threshold value for price discrepancy warnings." | |
) | |
price_variance_threshold_percent = fields.Float(help="Maximum variance (in percent) allowable between the product's standard price and purchase receipt unit price.") | |
price_variance_threshold_amount = fields.Float(help="Maximum allowable variance (in monetary amount, based on company currency) between the product's standard price and the purchase receipt unit price.") |
The idea is to allow both types of thresholds. Hitting either one should trigger an error.
class Stockpick(models.Model): | ||
_inherit = "stock.picking" | ||
|
||
allow_price_inconsistency = fields.Boolean( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
allow_price_inconsistency = fields.Boolean( | |
bypass_price_variance_check = fields.Boolean( |
for pick in self: | ||
if pick.picking_type_id.code != "incoming": | ||
continue | ||
if pick.sudo().allow_price_inconsistency: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why sudo()
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This field is only allowed for some group and we will get access right error if the user is not in this group.
product = move.product_id | ||
threshold_type = ( | ||
product.price_discrepancy_threshold_type | ||
or pick.company_id.price_discrepancy_threshold_type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Values from the company should be kept in variables outside the loop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Partial review.
bypass_price_variance_check = fields.Boolean( | ||
copy=False, | ||
tracking=True, | ||
groups="purchase_stock_price_variance.group_bypass_price_variance_check", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be better to extend write() to check if the user belongs to this group? I think this group assignment to the field is too rigid.
product.price_variance_threshold_amount | ||
or global_price_variance_threshold_amount | ||
) | ||
received_price = move.price_unit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should be safer this way to update the cost based on the current exchange rate.
received_price = move.price_unit | |
received_price = move._get_price_unit() |
continue | ||
if pick.sudo().bypass_price_variance_check: | ||
continue | ||
for move in pick.move_ids_without_package: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason for not using pick.move_ids
?
if pick.picking_type_id.code != "incoming": | ||
continue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please check if adding conditions using _is_in()
and _is_dropshipped()
for each stock move record is more appropriate instead of this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I checked the odoo source code, checking picking_type_id.code
is used in stock
._is_in()
and _is_dropshipped()
is introduced in stock_account
and used them. In our module, stock_account
is part of dependency because we use purchase_stock
as a dependency. So, I think using _is_in()
and _is_dropshipped()
is more appropriate.
<field name="price_variance_threshold_percent" /> | ||
<field name="price_variance_threshold_amount" /> | ||
<field name="bypass_price_variance_check" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<field name="price_variance_threshold_percent" /> | |
<field name="price_variance_threshold_amount" /> | |
<field name="bypass_price_variance_check" /> | |
<field name="bypass_price_variance_check" /> | |
<field name="price_variance_threshold_percent" /> | |
<field name="price_variance_threshold_amount" /> |
and make the threshold fields invisible when bypass_price_variance_check
is true.
I did |
): | ||
raise UserError( | ||
_( | ||
f"Price discrepancy detected for {product.name}: " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
f"Price discrepancy detected for {product.name}: " | |
f"Price variance exceeding a threshold detected for {product.name}: " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please tidy the steps (with numbers, perhaps) and "correct" the line breaks.
This module checks for variance between the receipt price and the product's | ||
standard price at the time of validation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This module checks for variance between the receipt price and the product's | |
standard price at the time of validation. | |
This module checks the variance between the purchase price and the product's | |
standard price at the time of receipt picking validation and displays an error if the | |
variance exceeds a given threshold. |
A warning message will be displayed during validation if the variance | ||
between the receipt price and the standard price exceeds the threshold. | ||
|
||
Selecting 'Bypass Price Variance Check' allows users to bypass this error, | ||
and it is only visible to members of the 'Bypass Price Variance Check' | ||
group. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A warning message will be displayed during validation if the variance | |
between the receipt price and the standard price exceeds the threshold. | |
Selecting 'Bypass Price Variance Check' allows users to bypass this error, | |
and it is only visible to members of the 'Bypass Price Variance Check' | |
group. | |
An error message will be displayed during validation if the variance | |
between the purchase price and the standard price exceeds a threshold. | |
Selecting 'Bypass Price Variance Check' in the receipt picking allows users | |
to bypass this error. Only members of the 'Bypass Price Variance Check' | |
group can update this field. |
self.env.company.price_variance_threshold_amount | ||
) | ||
for pick in self: | ||
if pick.sudo().bypass_price_variance_check: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if pick.sudo().bypass_price_variance_check: | |
if pick.bypass_price_variance_check: |
@AungKoKoLin1997 Sorry, missed this comment. I think the default of the product should be false, and have another field in res.config.settings to enable the feature. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code review.
if ( | ||
percentage_difference > threshold_percent | ||
or amount_difference > threshold_amount | ||
): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AungKoKoLin1997
I'm doing the functional test.
Currently, two problems arise.
- The initial threshold value is 0, so if the variance check is set to true and other thresholds are not changed, all products will not be able to be received.
- Both percentage and fixed values are used for variance, making it difficult to continue adjusting those values.
When I consulted Tashiro-san, he said that when it was 0, it would be best to avoid using that threshold.
I thought so too.
I think it's a good idea to separate the process by threshold to see if they're using that value, and if they're using them, check if they're above the threshold.
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nobuQuartile Please remove the pre-commit noise from other modules.
threshold_percent != 0 and percentage_difference > threshold_percent | ||
) or (threshold_amount != 0 and amount_difference > threshold_amount): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
threshold_percent != 0 and percentage_difference > threshold_percent | |
) or (threshold_amount != 0 and amount_difference > threshold_amount): | |
threshold_percent and percentage_difference > threshold_percent | |
) or (threshold_amount and amount_difference > threshold_amount): |
price_variance_threshold_amount = fields.Float( | ||
help="Maximum allowable variance (in monetary amount, based on company currency)" | ||
" between the product's standard price and the purchase receipt unit price." | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's make sure that the values are positive here.
) | |
) | |
@api.constrains("price_variance_threshold_percent", "price_variance_threshold_amount") | |
def _check_price_variance_threshold(self): | |
for rec in self: | |
if rec.price_variance_threshold_percent < 0 or rec.price_variance_threshold_amount < 0: | |
raise ValidationError(_("The threshold values cannot be negative.")) |
<div class="o_setting_right_pane"> | ||
<label for="price_variance_threshold_percent" /> | ||
<div class="text-muted"> | ||
Maximum variance (in percent) allowable between the product's standard price and purchase receipt unit price. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maximum variance (in percent) allowable between the product's standard price and purchase receipt unit price. | |
Maximum variance (in percent) allowable between the product's standard price and purchase receipt unit price. | |
Keeping it at zero means that this threshold will not be checked. |
Please apply the same adjustments to all the relevant places.
</div> | ||
<div class="content-group"> | ||
<div class="mt16"> | ||
<field name="price_variance_threshold_percent" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure this is the correct way to put it. Please check it yourself, and do the same for all the relevant fields.
<field name="price_variance_threshold_percent" /> | |
<field name="price_variance_threshold_percent" /><span> %</span> |
@AungKoKoLin1997 @yostashiro Current Product Variant Options
Option1
Option2
Option3
I think Option3 is better. |
We decided not to change the code. Current Product Variant Options Set a value at the product level (+) |
4947