def undo(): """ Undo a sale, only available for 5 minutes after the sale creation args: [sale_id] """ sale = db((db.sale.id == request.args(0)) & (db.sale.created_by == auth.user.id) & (db.sale.is_done == True)).select().first() # undo timeout err = '' if not sale: err = T('Sale not found') if request.now > sale.created_on + timedelta(minutes=5): print sale.created_on err = T('Its too late to undo it') if err: session.info = err redirect(URL('default', 'index')) # return wallet payments for payment in db( db.payment.id_payment_opt == get_wallet_payment_opt()).select(): wallet = db( db.wallet.wallet_code == payment.wallet_code).select().first() wallet.balance += payment.amount wallet.update_record() undo_stock_removal(bag=sale.id_bag) session.info = T('Sale undone') redirect(URL('default', 'index'))
def undo(): """ Removes the last inventory, and restocks items according to the last system quantities. this operation is available only when the stocks produced by the inventory haven't been used (sold). The intended use of this action is to undo inventories commited by mistake (even though the commited inventory will be lost). args: [id_inventory] """ inventory = db.inventory(request.args(0)) if not inventory: session.flash = T("Inventory not found") redirect(URL('index', 'default')) if not inventory.is_done: session.flash = T("Inventory has not been applied") redirect(URL('index', 'default')) if inventory.created_by.id != auth.user.id: session.flash = T("Not your inventory") redirect(URL('index', 'default')) # remove the items that were added by the inventory used = not db((db.stock_item.id_inventory == inventory.id) & ( db.stock_item.stock_qty != db.stock_item.purchase_qty)).isempty() # do not allow when the items introduced by an inventory has been sold if used: session.info = T('Inventory has been used, you can not undo it') redirect(URL('default', 'index')) # inventory not used, we can proceed # restore stocks for inventory items undo_stock_removal(inventory=inventory, remove=False) inventory.is_done = False inventory.update_record() session.info = T('Inventory undone') redirect(URL('inventory', 'index'))
def undo(): """ Removes the last inventory, and restocks items according to the last system quantities. this operation is available only when the stocks produced by the inventory haven't been used (sold). The intended use of this action is to undo inventories commited by mistake (even though the commited inventory will be lost). args: [id_inventory] """ inventory = db.inventory(request.args(0)) if not inventory: session.flash = T("Inventory not found") redirect(URL('index', 'default')) if not inventory.is_done: session.flash = T("Inventory has not been applied") redirect(URL('index', 'default')) if inventory.created_by.id != auth.user.id: session.flash = T("Not your inventory") redirect(URL('index', 'default')) # remove the items that were added by the inventory used = not db( (db.stock_item.id_inventory == inventory.id) & (db.stock_item.stock_qty != db.stock_item.purchase_qty) ).isempty() # do not allow when the items introduced by an inventory has been sold if used: session.info = T('Inventory has been used, you can not undo it') redirect(URL('default', 'index')) # inventory not used, we can proceed # restore stocks for inventory items item_utils.undo_stock_removal(inventory=inventory, remove=False) inventory.is_done = False inventory.update_record() session.info = T('Inventory undone') redirect(URL('inventory', 'index'))
def undo(): """ Undo a sale, only available for 5 minutes after the sale creation args: [sale_id] """ sale = ( db((db.sale.id == request.args(0)) & (db.sale.created_by == auth.user.id) & (db.sale.is_done == True)) .select() .first() ) # undo timeout err = "" if not sale: err = T("Sale not found") if request.now > sale.modified_on + timedelta(minutes=5): err = T("Its too late to undo it") if err: session.info = err redirect(URL("default", "index")) # return wallet payments for payment in db( (db.payment.id_payment_opt == get_wallet_payment_opt()) & (db.payment.id_sale == sale.id) ).select(): wallet_utils.transaction( payment.amount, wallet_utils.CONCEPT_UNDO_PAYMENT, ref=payment.id, wallet_code=payment.wallet_code ) if sale.id_client: wallet_utils.transaction( sale.reward_points, wallet_utils.CONCEPT_UNDO_SALE_REWARD, ref=sale.id, wallet_id=sale.id_client.id_wallet.id, ) undo_stock_removal(bag=sale.id_bag) session.info = T("Sale undone") redirect(URL("default", "index"))