Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

Cancel Sales Order after Delivered Items

By
Jihen BEN ALI
on 10/19/16, 12:49 PM 109 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

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 10/19/16, 12:49 PM
Seen: 109 times
Last updated: 10/19/16, 2:40 PM