跳至內容
選單
此問題已被標幟
4 回覆
3282 瀏覽次數

Hello,

In sale order line I don't want Odoo to update price automatically when I change the quantity because sometime, I change the price manually and then change the quantity so I need to keep the price. Please help!

頭像
捨棄
最佳答案

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:


頭像
捨棄
最佳答案

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

頭像
捨棄

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

最佳答案

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,

頭像
捨棄
最佳答案

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()

頭像
捨棄