Hi,
You can achieve this with a lightweight Odoo customization using @api.onchange.
Here’s the Python code for a small module that adds this behavior.
from odoo import api, fields, models
class SaleOrderLine(models.Model):
_inherit = "sale.order.line"
final_price = fields.Float(
string="Final Unit Price",
help="Enter the final selling price per unit; discount will be calculated automatically."
)
@api.onchange('final_price')
def _onchange_final_price(self):
for line in self:
if line.final_price and line.product_id:
list_price = line.product_id.lst_price
if list_price > 0:
discount = (1 - (line.final_price / list_price)) * 100
line.discount = discount
line.price_unit = list_price
else:
line.discount = 0.0
* Adds a new field final_price on sale order lines.
* When you enter a final_price, it:
-Sets the Unit Price to the product’s list price.
-Calculates and fills the Discount % field automatically.
* This ensures accounting, taxes, and reports continue to use Odoo’s built-in fields.
Option 2 — Odoo Studio (No Code Alternative)
If you use Odoo Enterprise, you can implement a simpler version with Odoo Studio:
Open Sales → Orders → Order Lines.
Activate Studio and add a new field called Final Price.
Add an Automated Action (triggered on change of Final Price) with Python code:
if record.product_id and record.final_price:
list_price = record.product_id.list_price or 0
if list_price > 0:
record.discount = (1 - (record.final_price / list_price)) * 100
record.price_unit = list_price
Save and test — when you edit Final Price, Odoo will auto-calculate the discount.
Related module:-
* https://apps.odoo.com/apps/modules/18.0/sale_discount_total
Hope it heps