Skip to Content
Menu
You need to be registered to interact with the community.
This question has been flagged
3 Odgovori
146 Prikazi

Hi everyone,


I’m working with Odoo (v18,v19) and I’ve noticed that in quotation/order lines you can only change the discount percentage — not the final unit price directly.


What I’d like to do is the opposite:

👉 Enter the final price per unit, and have Odoo automatically calculate the discount based on the list price.


Example:

  • Product list price = €100
  • I type the final price = €85
  • Odoo automatically sets the discount to 15%


Has anyone already implemented this behavior or knows how to achieve it (e.g. via Studio, automated action, or a small customization)?


Thanks in advance for any ideas or examples!

Avatar
Opusti
Best Answer

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

Avatar
Opusti
Best Answer

Hello George,



Odoo calculates the final price based on the list price and discount to maintain pricing consistency. Here’s how you can achieve your desired functionality:


  Using Odoo Studio:
    If you have Odoo Studio, you can create an automated action on the 'Sale Order Line' model.

    This action should trigger when the 'price_unit' (final price) field is changed.

    The action will calculate the discount percentage based on the list price and the entered final price: discount = ((list_price - final_price) / list_price) * 100

    Then, it will update the 'discount' field with the calculated percentage.

  Custom Module:
    Alternatively, a custom module would provide more control.

    You’d create a new module and inherit the 'sale.order.line' model.

    Override the 'price_unit' field's onchange method to compute the discount and update the discount field, similar to the Odoo Studio approach.


For personalized assistance:
https://www.pragtech.co.in/contact-us-mql.html

Avatar
Opusti
Best Answer

Hello George,



Odoo's standard behavior focuses on managing discounts from the list price to maintain pricing consistency. To achieve your goal of directly inputting the final price and automatically calculating the discount, here’s how you can approach it:


  Using Odoo Studio (if available):
    Add a new computed field to the sale order line.

    This field will allow you to enter the desired final price.

    Create an automated action that triggers when the final price field is modified.

    This action should calculate the discount percentage based on the list price and the entered final price and then update the discount field.

  Custom Module Development:
    Create a custom module to extend the sale order line model.

    Add a new field for the final price.

    Override the write method of the sale order line to calculate the discount when the final price is entered.

    Update the discount field accordingly.

  Automated Actions (Less Recommended):
    While possible, using automated actions alone might become complex due to the need to handle various scenarios and dependencies.


For personalized assistance:
https://www.pragtech.co.in/contact-us-mql.html

Avatar
Opusti
Related Posts Odgovori Prikazi Aktivnost
1
nov. 20
5212
1
mar. 23
24077
1
mar. 15
10411
1
avg. 23
1758
0
sep. 21
1734