Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
171 Lượt xem

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!

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 11 20
5216
1
thg 3 23
24089
1
thg 3 15
10418
1
thg 8 23
1772
0
thg 9 21
1739