This question has been flagged
2 Replies
3358 Views

Hello everyone,

I need to cancel sale order when items were delivered I could do it but my problem is the quantity is not changing any help please

Just how to update available_quantity

def action_cancel(self, cr, uid, ids, context=None):
res = super(account_invoice, self).action_cancel(cr, uid, ids, context=context) payment_line_obj = self.pool.get('payment.line') product_obj = self.pool.get('product.product') for inv in self.browse(cr, uid, ids, context=context):
# cr.execute("""SELECT DISTINCT order_id FROM sale_order_invoice_rel # WHERE invoice_id = ANY(%s)""", (list(ids),)) sale = inv.sale_order_id or False purchase = inv.purchase_order_id or False if sale:
print 'sale:',sale print 'picking',sale.picking_ids.id if sale.shipped == True:
stock_id= self.pool.get('stock.move').search(cr, uid,[('picking_id','=',sale.picking_ids.id)], context=context) stock= self.pool.get('stock.move').browse(cr, uid, stock_id, context=context) for ss in stock:
if ss.state == 'done':
going = ss.product_qty print 'going:',going prod_id = product_obj.search(cr, uid, [('id','=',ss.product_id.id)], context=context) prod = product_obj.browse(cr, uid, prod_id) for pp in prod:
print 'qty_available:',pp.qty_available qty = pp.qty_available + going print 'qty:',qty virtual_available = pp.virtual_available + going print 'virtual_available:',virtual_available print 'prod_id:',pp.id n= product_obj.write(cr, uid, [pp.id],{'qty_available': qty})# n = nn.write({'qty_available':qty_available, 'virtual_available': virtual_available}, context=context) print 'n:',n if n == True: nn = product_obj.browse(cr, uid, [pp.id]) print 'nn:',nn print 'hhh:',nn.qty_available k = self.pool.get('stock.move').write(cr, uid, ss.id, {'state':'cancel'}) picking = self.pool.get('stock.picking').browse(cr, uid, sale.picking_ids.id) print 'picking:',picking.state cancel_picking = picking.write({'state':'draft'}) print 'cancel_picking:',cancel_picking print 'picking_state:',picking.state# if cancel_picking==True:
# bb = self.pool.get('stock.picking').action_cancel(cr, uid, sale.picking_ids.id, context=context)# if picking.state == 'cancel':
# ee = self.pool.get('stock.picking').unlink(cr, uid, sale.picking_ids.id, context=context)# print 'ee:',ee aa = self.pool.get('sale.order').write(cr,uid,sale.id,{'state':'cancel'}) if aa==True:
aaa = self.pool.get('sale.order').browse(cr, uid, sale.id) print 'aaa:',aaa.state ff = aaa.unlink() print 'ff:',ff print "sale_cancel:" ,aa
Avatar
Discard
Best Answer

Hello,

You can cancel sale order by this app, even after deliver items. By click on this , Cancel Sale Order App link.

https://apps.odoo.com/apps/modules/11.0/cancel_sale_order/

 

Thanks

Avatar
Discard
Best Answer

Hello,

There is one app available at odoo store which will cancel shipped sales order.


Quick View

  • Cancel Delivery Orders attached with Sales Order, even if those are processed.

  • While cancel delivery order, it will affect stock & remove journal entries (If any) created for stock valuation.

  • Cancel Invoices which are created from the sales order.

  • If payment is made for an invoice, it will unreconciled a payment from the invoice & cancel it.


Click Cancel & Reset to Draft Sales Order In Odoo to know more.

Avatar
Discard