[ADD] product_pricelist_total_margin: New module for additive margin calculation

- Add use_total_margin field to pricelist items
- Override _compute_price() to sum margins additively instead of compounding
- Support chained pricelists with custom base types (last_purchase_price)
- Add global minimum and maximum margin limits configuration
- Store limits in ir.config_parameter via res.config.settings
- Apply global limits after total margin calculation
- Add comprehensive test suite (9 tests) covering:
  * Basic additive vs compound margin behavior
  * Three-level pricelist chains
  * Global minimum/maximum margin enforcement
  * Rounding and surcharge compatibility
- Add configuration UI in Settings > Sales
- All tests passing (9/9)

This module fixes the issue where chained pricelists were compounding margins
instead of calculating total margins. Example: base 4.68€ with -5% and +25%
now correctly results in 5.616€ (20% total) instead of 5.56€ (compound).
This commit is contained in:
snt 2026-02-21 16:11:13 +01:00
parent f35bf0c5a1
commit 32f345bc44
12 changed files with 1143 additions and 0 deletions

View file

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="product_pricelist_item_form_view_inherit" model="ir.ui.view">
<field name="name">product.pricelist.item.form.inherit.total.margin</field>
<field name="model">product.pricelist.item</field>
<field name="inherit_id" ref="product.product_pricelist_item_form_view" />
<field name="arch" type="xml">
<!-- Add use_total_margin field after compute_price -->
<field name="compute_price" position="after">
<field
name="use_total_margin"
invisible="compute_price != 'formula' or base != 'pricelist'"
/>
</field>
</field>
</record>
</odoo>

View file

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="res_config_settings_view_form" model="ir.ui.view">
<field name="name">res.config.settings.view.form.inherit.total.margin</field>
<field name="model">res.config.settings</field>
<field name="priority" eval="90" />
<field name="inherit_id" ref="sale.res_config_settings_view_form" />
<field name="arch" type="xml">
<xpath expr="//setting[@id='pricelist_configuration']" position="after">
<setting id="total_margin_limits" string="Total Margin Limits" help="Set minimum and maximum margin percentages for Total Margin Mode">
<div class="content-group">
<div class="row mt16">
<label
string="Minimum Margin (%)"
for="total_margin_min_percent"
class="col-lg-3 o_light_label"
/>
<field name="total_margin_min_percent" class="oe_inline" />
</div>
<div class="row">
<label
string="Maximum Margin (%)"
for="total_margin_max_percent"
class="col-lg-3 o_light_label"
/>
<field name="total_margin_max_percent" class="oe_inline" />
</div>
</div>
</setting>
</xpath>
</field>
</record>
</odoo>