Thursday, December 23, 2021
1 change · master
Code cleanup and technical improvements
This update streamlines how Odoo calculates product and sales prices, reducing hidden assumptions that could lead to inconsistent results. It improves maintainability across sales, products, point of sale, events, expenses, and repairs, making future pricing changes safer and easier to customize.
Original PR description
Refactor the whole sale price computation logic in `product` & `sale` to improve code quality, maintainability, ... ### Drop/reduce as much as possible context-based logic * Drop magic `price` and…
Refactor the whole sale price computation logic in `product` & `sale` to improve code quality, maintainability, ... ### Drop/reduce as much as possible context-based logic * Drop magic `price` and `pricelist_id` fields on `product.product`/`product.template` * Keep one unique `_get_contextual_price()` to provide the old logic where it's still needed/difficult to remove atm. * Do not rely on context fallbacks on the lower level of price computation (aka `price_compute` method) It is way too dangerous to have such magic fallbacks so deeply in the logic, inducing potentially unexpected/wrong results ### Clean `product.pricelist` API * Clear parameters and fallbacks * Do not provide unused parameter(s) anymore (`partner`) * Stop providing products & quantities as a list of tuples, it was never used with different quantities in the existing code anyway * Removed unused methods * Split methods logic to ease and allow clean overrides and customizations * Convert the old hardcoded SQL query to a clear domain, using ORM querying and formatting logic instead * Improved documentation (docstrings, ...) ### Side cleanups in related/impacted modules * Update to use the new clean pricelist API * Code cleanup in sale prices computation (`sale_*`, `website_sale`, ...) * Some onchanges -> computes conversion in `sale_*` scope * Cache applied pricelist rule on SOL (avoid recomputing the pricelist rule in the price AND in the discount computation) Task ID - 2688106 Community PR: https://github.com/odoo/odoo/pull/79605 Enterprise PR: https://github.com/odoo/enterprise/pull/22211 <!-- Keep both authorship for the merge commit (author=robodoo) --> Co-authored-by: Victor Feyens <vfe@odoo.com> Co-authored-by: Yannick Tivisse <yti@odoo.com> -- I confirm I have signed the CLA and read the PR guidelines at www.odoo.com/submit-pr