[FIX] sale_management: update global discount when order lines change#1297
Open
times-odoo wants to merge 3 commits into
Open
[FIX] sale_management: update global discount when order lines change#1297times-odoo wants to merge 3 commits into
times-odoo wants to merge 3 commits into
Conversation
6dc7b3a to
d3b40e6
Compare
When a global discount line is applied to a sale order and an order line is removed, the discount amount was not recalculated, leaving an incorrect discount value on the order. Added an onchange on order_line that recomputes the discount line amount based on the updated subtotal of remaining product lines. If no product lines remain, the discount line is removed entirely. task-6245598
a05267e to
bebdee0
Compare
…xt updates Introduced a tracking field for global discount percentages and added logic to dynamically update it based on modifications made directly to the discount line description. Rationale: Users need a synchronized flow when modifying global discount values. By introducing 'global_discount_percentage', the system preserves the raw numerical float value for other computing methods while allowing changes made inside the line item description text to drive the value update. Additionally, extracting the decimal precision dynamically ensures that line renaming remains visually clean, localized, and compliant with system-configured currency rounding standards. Technical choices: - Added the 'global_discount_percentage' Float field to 'sale.order'. - Updated '_onchange_update_global_discount' to extract and validate descriptions, raising a UserError if a proper float structure is missing. - Implemented state-change detection to synchronize the field value only when 'discount_from_name' shifts. - Leveraged 'decimal.precision' and 'float_repr' to construct dynamically formatted, localized description strings using Odoo's 'self.env._' method.
bebdee0 to
8e51626
Compare
…ng notifications on invalid discount names
Refactored the onchange string validation to utilize non-blocking bus
notifications and safely fall back to the original database record state.
Rationale:
Raising a strict 'UserError' inside an '@api.onchange' method breaks the
user's input flow harshly and can cause unstable UI behaviors in the web
client. Replacing the error with a bus notification improves the user
experience by warning them gracefully while resetting the line description
back to its last saved valid state ('self.id.origin'). Additionally, fixed
the wizard mapping computation to correctly store the percentage value as a
whole float number (multiplied by 100) to remain consistent with backend
expectations.
Technical choices:
- Replaced 'UserError' with 'self.env.user._bus_send' to broadcast a
non-blocking UI warning snippet.
- Leveraged 'self.id.origin' via a database browse to retrieve the last
committed 'global_discount_percentage' value as a dependable fallback.
- Restructured string evaluation inside the onchange loop to immediately
return after rebuilding the description string, stopping unexpected line mutation.
- Corrected the transient wizard assignment math by multiplying the scalar representation
by 100 before writing it to the core sales document.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Ensure the global discount value dynamically updates or resets when order lines are modified, utilizing a centralized field synchronized with manual line updates.
The implementation covers:
Task Reference: 6245598