Help

欢迎!

该社区面向专业人士和我们产品和服务的爱好者。
分享和讨论最好的内容和新的营销理念,建立您的专业形象,一起成为更好的营销人员。


0

Don't want Odoo to update price when changing quantity

Avatar
odoo
Avatar
Discard
4 Answers
0
Avatar
odoo
Best Answer

you can customize the behavior by overriding the relevant method in the sale.order.line model. Here's an example of how you can achieve this:

  1. Create a custom module:

    • Create a custom module or use an existing one to implement the required customization. Let's assume the module name is custom_sale.
  2. Inherit the sale.order.line model:

    • In the custom_sale/models/sale_order.py file, define a new Python class that inherits from sale.order.line:
from odoo import models, api
classSaleOrderLine(models.Model):
    _inherit = 'sale.order.line'    

@api.onchange('product_uom_qty')
defonchange_product_uom_qty(self): # Skip price update if price has been manually set
for line in self: if line.price_unit_manual: continue
​ else: # Call the original onchange method to update the price
super(SaleOrderLine, line).onchange_product_uom_qty()



  1. Update the module manifest:
    • In the custom_sale/__manifest__.py file, add the dependency on the sale module:


Avatar
Discard
0
Avatar
odoo
Best Answer

HI,

By default there is no option to disable it. If you need to achieve this you have add custom codes into the system, which will do the same for you.

The case is that, odoo has the functionality of the price list, where the price can change based on the number of quantities we are selling, once you applied this change, you will loose this functionality in the system.


Anyway if you need to achieve this, you have to create a custom module, which inherit the sale.order.line model and remove the product_uom_qty dependency from _compute_price_unit function.


Thanks

1 Comment
Avatar
Discard
Avatar
odoo
-

am sorry , the function is def _compute_price_unit(self): in the sale order line model

0
Avatar
odoo
Best Answer

Hi!

This behavior was changed in Odoo 18, please have a look at the following video (starting from 12:40): https://www.odoo.com/odoo/project/809/tasks/4035579

Once you've upgraded the database to 18, you'll have access to the new feature. 

Hope this helps,

Avatar
Discard
0
Avatar
odoo
Best Answer

This solution doens't work for me,


You can made override of function to avoid update:


from odoo import _, api, models, fields

class SaleOrderLine(models.Model): @api.depends('product_id', 'product_uom', 'product_uom_qty')
def _compute_price_unit(self):
for line in self:
if line.price_unit > 0:
continue
else:
super(SaleOrderLine, line)._compute_price_unit()

Avatar
Discard