[MIG] sale_margin_percentage: Migration to 19.0 T#98917#1728
[MIG] sale_margin_percentage: Migration to 19.0 T#98917#1728JesusValdez96 wants to merge 17 commits into
Conversation
f1302a3 to
2f72027
Compare
By this way, the sale order gross margin percentage is calculated by the sum all the margin lines between the inverse sum of all subtotals. Module features: - Field to configure Margin Threshold on sale settings. - Colors in sale order lines to point the margin threshold. - Fix to 100 margin percentage when purchase price is not set. - Fix to -100 margin percentage when price unit is not set. Fix to 0 margin percentage when product quatity is 0.
The sale.config.settings view was changed completely after v10.0, in this fix we have moved margin_threshold field from old sale settings view to the new one.
The following is performed: - Added group for managing sales percentages. - Updated translations and test modifications. - Modifications made for test execution. - Added the 'for' attribute inside the labels.
Migration process from v12.0 to v15.0
So calculations work correctly.
To follow our good practices each model should be in its own file with the same name as the model.
… of native one The field margin_percentage is no longer needed since native module sale_margin have the field margin_percent that serve the same propose. Also the field margin_threshold must be updated since it was used as a percentage but the native field margin_percent is a ration so we must follow the same pattern.
There's a migration script to recompute sales marging on sale order lines, which was raising memory errors with databases that contain many lines. The following optimizations are applied: - Don't call compute method directly but mark the field to be computed. This avoids one write per record and makes the ORM to take care of batches. - Read currency directly from the line, instead of from the pricelist which in turn requires reading the order. - Don't read currency if quantity is zero as it won't be used anyway
This module was originally created in v11 for a specific customer, and the purchase price needed to be non-editable for some reason. Now the purchase price does not need to be non-editable. If it is needed, it should be managed in the view because the field is natively editable.
This commit migrates the sale_margin_percentage module to Odoo 19.0 with the following changes: - Adapt settings and sales views to the 19.0 architecture, replacing deprecated settings markup and updating order line list. - Add a stored margin alert helper to keep line decorations without relying on the restricted margin percent field in the view. - Update security and test definitions to match the newer API changes. - Remove the obsolete post-migration script and bump the module version to 19.0.1.0.0. Related to T#98917
2f72027 to
9e54494
Compare
|
@ysantiago could you review? Please |
|
@luisg123v Please, rewiew |
luisg123v
left a comment
There was a problem hiding this comment.
Regarding commit message:
- "bump the module version": Remove this part, this is an "obvious" change
- Fix indentation on multiline list items
- Remove task ID from commit message
| "views/sale_order_views.xml", | ||
| "views/res_config_settings_views.xml", | ||
| ], | ||
| "installable": True, |
There was a problem hiding this comment.
Do this in the source version, with a commit similar to #1730. Then bring that commit here as part of the history.
| msgid "" | ||
| msgstr "" | ||
| "Project-Id-Version: Odoo Server 15.0+e\n" | ||
| "Project-Id-Version: Odoo Server 19.0+e\n" |
There was a problem hiding this comment.
You only updated the version, because dates were not updated and the new terms (the selection field) are not present.
You should re-generate the file by exporting translations again.
| ], | ||
| compute="_compute_margin_alert", | ||
| store=True, | ||
| compute_sudo=True, |
There was a problem hiding this comment.
- Why stored?
- Stored fields are already
compute_sudo
| <xpath expr="//field[@name='order_line']/tree//field[@name='purchase_price']" position="after"> | ||
| <field name="margin_threshold" invisible="1" /> | ||
| <xpath expr="//field[@name='order_line']/list//field[@name='purchase_price']" position="after"> | ||
| <field name="margin_threshold" column_invisible="1" /> |
There was a problem hiding this comment.
It's no longer required to add invisible fields to be able to use them in other field's attributes, See odoo/odoo#137031 for more information.
| id="margin_percentage" | ||
| string="Margin Threshold" | ||
| help="Minimum margin percentage allowed" | ||
| invisible="not module_sale_margin" |
There was a problem hiding this comment.
This condition will never be met, since installing this module will also install sale_margin.
| _inherit = "sale.order.line" | ||
|
|
||
| margin_threshold = fields.Float( | ||
| default=lambda self: self.env.user.company_id.margin_threshold, help="Limit margin set in sales configuration" |
There was a problem hiding this comment.
- Migrate to
self.env.company. - If you change the order's company, the threshold will be oupdated, won't it?
| "demo/product_product_demo.xml", | ||
| ], | ||
| "data": [ | ||
| "security/sale_margin_percentage_security.xml", |
There was a problem hiding this comment.
Rename to:
| "security/sale_margin_percentage_security.xml", | |
| "security/res_groups_security.xml", |
In the source version.
| @@ -0,0 +1,53 @@ | |||
| .. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg | |||
There was a problem hiding this comment.
- License is LGPL, not AGPL
- Licence → license
Do this in the source version.
| """Test cases for sale.order model""" | ||
|
|
||
| def setUp(self): | ||
| super().setUp() |
| def setUp(self): | ||
| super().setUp() | ||
| self.partner = self.env.ref("base.res_partner_12") | ||
| self.product_cost_0 = self.env.ref("product.product_product_4") |
There was a problem hiding this comment.
Since data demo is no longer lodaded by default, we can no longer depen on it in the tests.
This commit migrates the sale_margin_percentage module to version 19.0 with the following changes:
version to 19.0.1.0.0.
Related to T#98917