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

Hi all,

i'm trying to unlink sale order line items withing my custom onchange( ) function. 

when i run my function it unlink the item with all saleorder details such as customer details and others.

so if you have any method to unlink only saleorder line item without deleting other details.please let me know.

bellow is my custom onchange function.



@api.onchange('order_line')
def onchange_product_id_check_availability(self):
for ordr_ln in self.order_line:

if ordr_ln['product_id']:
stock_qun_obj = self.env['stock.quant'].search([('location_id', '=', self.location_obj_id), ('product_id', '=', ordr_ln['product_id'].id)])
tot_quantity = 0
tot_reserved_quantity = 0
for qunt in stock_qun_obj:
if qunt.quantity < 0 and qunt.reserved_quantity < 0:
tot_quantity = tot_quantity
tot_reserved_quantity
else:
tot_quantity = tot_quantity + qunt.quantity
tot_reserved_quantity = tot_reserved_quantity + qunt.reserved_quantity

# self.qty_available = stock_qun_obj.quantity - stock_qun_obj.reserved_quantity
ordr_ln['qty_available'] = tot_quantity - tot_reserved_quantity

if ordr_ln.product_uom_qty:
# raise ValidationError(ordr_ln.id.name)
if ordr_ln['qty_available'] < ordr_ln.product_uom_qty:
warning_mess = {
'title': ('Opps! Not enough stock'),
'message': (
'Not enough Stock on This product')
}
ordr_ln.id.unlink()        
Avatar
Discard
Best Answer

Hi,

To delete a sale order line , do like this

for line in self.order_line:
line.unlink()

This will remove only the order lines, if you want to remove only then add some condtion inside the for loop and unlink it

for line in self.order_line:
    if line.something == '0':
        #add a condition and unlink based on it
    line.unlink()

Thank you

Avatar
Discard
Author

@Niyas,

I did that niyas.but it's remove customer name, customer details and other relevant details as well. that's the issue i have now.