Skip to Content
Menu
This question has been flagged
1 Reply
554 Views

Hello,

i overrided create methode of sale.order.line method and i added in the values dictionnary, the field discount with a percentage, for example, 10

The line is created but the discount is not 10 but 0

Do you know why my discount is not taking into account and how i can do that ?

Note : I don't explain all the customer request but i can't use pricelist

Avatar
Discard
Best Answer

Hello,


def create(self, cr, uid, values, context=None):

    if context is None:

        context = {}

    if 'discount' in values:

        values['discount'] = values['discount'] / 100.0

    return super(sale_order_line, self).create(cr, uid, values, context=context)


In this example, the discount value is divided by 100 before the create method is called on the parent class. This converts the discount from a percentage to a decimal, which is the format Odoo expects for discounts.

Hope this helps.

Avatar
Discard
Author

Hello Maciej,

Thank you for your answer, i tried your solution but it is the same result.
Here is the values just before call create method of the parent class
values={'order_id': 521, 'product_id': 21, 'product_uom_qty': 1.0, 'product_uom': 1, 'task_id': 773, 'qty_delivered': 1.0, 's_equipement_id': 91060, 'discount': 0.1}

We can see that the discount is inside with the 10% divided by 100 but when i open the order, the line is created but the discount = 0

I see, it seems like the discount is not being applied even though you’re setting it in the values dictionary before calling the create method. You could check also this:

Discount Field Configuration: Ensure that the discount field is properly configured in your Odoo settings. You can do this by going to Sales module -> Configuration -> Settings -> Pricing and enabling Sale Discount Approval.

Author

I already verified this option and it is checked
Although i can change manually the discount in the sale.order view and it works but not with python.
It is like my discount in the dictionnary is overwrote by zero, maybe because i don't use pricelist !